Delphi Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
NTLM
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

Type Conversion

 

Article: Understanding COM References in Delphi

The Chilkat StringArray object

The Chilkat string array object is a utility class used by many of the Chilkat components. It's not an array. It's an object that contains 0 or more strings that can be retrieved by index. The reason Chilkat created this object is that string arrays are handled differently in different programming languages. The CkStringArray object (or Chilkat.StringArray in .NET) is used whenever a collection of strings is passed to a method, or returned from a method. This example demonstrates some very basic usage. How to create a string array, populate it with some entries, sort it, retrieve entries, etc.

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATUTILLib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
sa: TCkStringArray;
n: Integer;
i: Integer;
ascending: Integer;
useCrlf: Integer;
serialized: String;
sa2: TCkStringArray;
index: Integer;
startIndex: Integer;

begin
//  This is not an array -- it's an object.
sa := TCkStringArray.Create(Self);

//  Append some strings.
sa.Append('abc');
sa.Append('Abc');
sa.Append('123');
sa.Append('Chilkat Software, Inc.');

//  How many strings?

n := sa.Count;
Memo1.Lines.Add(IntToStr(n));

//  Iterate over the strings contained in the object:

for i := 0 to n - 1 do
  begin
    Memo1.Lines.Add(sa.GetString(i));
  end;

//  Sort in ascending order:

ascending := 1;
sa.Sort(ascending);

Memo1.Lines.Add('Sorted:');
for i := 0 to n - 1 do
  begin
    Memo1.Lines.Add(sa.GetString(i));
  end;

//  Save to a file (one string per line).
//  Line endings are controlled by the Crlf property.
useCrlf := 1;
sa.Crlf := useCrlf;
sa.SaveToFile('strings.txt');

//  Clear the string array.
sa.Clear();

//  Load the string array from a file.  Each line in the
//  file becomes a string contained in the object:
sa.LoadFromFile('strings.txt');

//  Remove a string by exact match:
sa.Remove('abc');

//  Remove a string by index (1st string is at index 0):
sa.RemoveAt(2);

//  The Trim property can be set to automatically trim whitespace
//  from the beginning and end of any string added to the object:
sa.Trim := 1;

//  Append some strings from a comma-separated list:
sa.SplitAndAppend('apple, orange, banana, pear, lime',',');

//  What do we have now?
Memo1.Lines.Add('-------- After SplitAndAppend:');
n := sa.Count;
for i := 0 to n - 1 do
  begin
    Memo1.Lines.Add(sa.GetString(i));
  end;

//  Serialize the complete object to a base64 string:

serialized := sa.Serialize();

Memo1.Lines.Add('-------- Serialized:');
Memo1.Lines.Add(serialized);

//  Restore from a serialized string:
sa2 := TCkStringArray.Create(Self);
sa2.AppendSerialized(serialized);

Memo1.Lines.Add('-------- After AppendSerialized:');
n := sa2.Count;
for i := 0 to n - 1 do
  begin
    Memo1.Lines.Add(sa2.GetString(i));
  end;

//  Set the Unique property to prevent duplicates from being added:
sa.Unique := 1;
sa.Clear();
sa.Append('apple');
sa.Append('banana');
sa.Append('apple');
sa.Append('banana');

//  What do we have now?
Memo1.Lines.Add('-------- Unique strings:');
n := sa.Count;
for i := 0 to n - 1 do
  begin
    Memo1.Lines.Add(sa.GetString(i));
  end;

//  Find the location of a specific string
//  (case insensitive).

startIndex := 0;
index := sa.Find('apple',startIndex);
if (index >= 0) then
  begin
    Memo1.Lines.Add('found apple at index ' + IntToStr(index));
  end
else
  begin
    Memo1.Lines.Add('apple not found');
  end;


end;

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Email Component · XML Parser