Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Aufbau eines Array of Const (https://www.delphipraxis.net/114899-aufbau-eines-array-const.html)

nicodex 2. Jun 2008 16:27

Re: Aufbau eines Array of Const
 
Wie schon erwähnt, werden intern zwei Parameter übergeben (Länge bzw. Index des letzten Elements) und ein Zeiger auf das erste Element (TVarRec):
Delphi-Quellcode:
unit Foo;

interface

implementation

uses
  SysUtils,
  Dialogs;

procedure Bar(const AMethod: string; const AParams: array of const);
var
  Index: Integer;
  Text: string;
begin
  for Index := Low(AParams) to High(AParams) do
    with TVarRec(AParams[Index]) do
    begin
      case VType of
        vtInteger:   Text := 'vtInteger';
        vtBoolean:   Text := 'vtBoolean';
        vtChar:      Text := 'vtChar';
        vtExtended:  Text := 'vtExtended';
        vtString:    Text := 'vtString';
        vtPointer:   Text := 'vtPointer';
        vtPChar:     Text := 'vtPChar';
        vtObject:    Text := 'vtObject';
        vtClass:     Text := 'vtClass';
        vtWideChar:  Text := 'vtWideChar';
        vtPWideChar: Text := 'vtPWideChar';
        vtAnsiString: Text := 'vtAnsiString';
        vtCurrency:  Text := 'vtCurrency';
        vtVariant:   Text := 'vtVariant';
        vtInterface: Text := 'vtInterface';
        vtWideString: Text := 'vtWideString';
        vtInt64:     Text := 'vtInt64';
      else
        Text := '$' + IntToHex(VType, 2);
      end;
      ShowMessage('Parameter ' + IntToStr(Index) + ': ' + Text);
    end;
end;

initialization

  Bar('Foo', [42, 'Hello, World!', nil]);

end.

Neutral General 2. Jun 2008 16:31

Re: Aufbau eines Array of Const
 
Hi Nicodex,

Danke für dein Beispiel.

Das wäre nicht das Problem, aber ich habe gerade das Problem, das ich mit ASM rumfummeln muss und jetzt will ich den Wert des TVarRecs in ein Register kopieren.

Leider funktioniert:

mov eax,Params[0].VInteger

nicht.

Ich bekomme die Compilerfehlermeldung das VInteger undefiniert ist.

Gruß
Neutral General

nicodex 2. Jun 2008 16:34

Re: Aufbau eines Array of Const
 
Zitat:

Zitat von Neutral General
mov eax, Params[0].VInteger

Für Offsets musst du den Typen angeben:
mov eax, [xxx].TVarRec.VInteger

Neutral General 2. Jun 2008 16:40

Re: Aufbau eines Array of Const
 
Hi,

Danke für den Tipp. Also compilieren tuts, aber es steht nachher ein falscher Wert in ecx (Nicht wunder warum ich einmal von eax und einmal von ecx rede - das ist im Prinzip grad egal :mrgreen: ) :gruebel:

Habe herausgefunden, dass:

Delphi-Quellcode:
// 1 = 2 = 3
1   mov ecx,[Params[1]].TVarRec.VInteger // 22
2   mov ecx,[Params[1]]
3   mov ecx, Params[1]


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:11 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz