Das geht auch noch, hätte ich nicht gedacht
.
Den Teil musst du nur einmal sehen, dann kannst du ihn schnell in eine
Unit wegsperren
:
Delphi-Quellcode:
{$IFNDEF FILL_ARRAY_TEMPLATE}
unit FillArray_Template;
interface
type _ARRAY_ITEM_ = Integer;
{$ENDIF FILL_ARRAY_TEMPLATE}
{$IFNDEF FILL_ARRAY_TEMPLATE_SECOND_PASS}
type
_ARRAY_TYPE_ =
array of _ARRAY_ITEM_;
function FillArray(AItems:
array of _ARRAY_ITEM_): _ARRAY_TYPE_;
{$ENDIF FILL_ARRAY_TEMPLATE_SECOND_PASS}
{$IFNDEF FILL_ARRAY_TEMPLATE}
implementation
{$DEFINE FILL_ARRAY_TEMPLATE_SECOND_PASS}
{$ENDIF FILL_ARRAY_TEMPLATE}
{$IFDEF FILL_ARRAY_TEMPLATE_SECOND_PASS}
function FillArray(AItems:
array of _ARRAY_ITEM_): _ARRAY_TYPE_;
var
i: Integer;
begin
SetLength(Result, Length(AItems));
for i := 0
to High(Result)
do
Result[i] := AItems[i];
end;
{$IFNDEF FILL_ARRAY_TEMPLATE}
end.
{$ENDIF FILL_ARRAY_TEMPLATE}
{$ENDIF FILL_ARRAY_TEMPLATE_SECOND_PASS}
{$DEFINE FILL_ARRAY_TEMPLATE_SECOND_PASS}
Das Beispiel ist nicht ganz so hässlich:
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, FillArray_Template;
type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
{$DEFINE FILL_ARRAY_TEMPLATE}
type
_ARRAY_ITEM_ =
string;
{$INCLUDE FillArray_template.pas}
type
StringArray = _ARRAY_TYPE_;
implementation
{$R *.dfm}
{$INCLUDE FillArray_template.pas}
procedure TForm1.FormCreate(Sender: TObject);
var
s: StringArray;
i: Integer;
begin
s := FillArray(['
*blubb*', '
Hello', '
World', '
*blubb*']);
for i := 0
to High(s)
do
ShowMessage(s[i]);
end;
end.