this slowpoke moves

Variable Api Call

program APICall;

{$APPTYPE CONSOLE}

uses
  Windows,
  SysUtils;

type
  PStringInfo = ^TStringInfo;
  TStringInfo = packed record
    iRefCount   : Integer;
    iLenCount   : Integer;
    pStringAddr : Pointer;
  end;

procedure ShowStringInfo(const s: String);
var
  p: PStringInfo;
begin
  p := Pointer(s);
  Dec(Integer(p), 8);

  WriteLN(Format('  String:        %s', [s]));
  WriteLn(Format('  p.RefCount:    %d', [p^.iRefCount]));
  WriteLn(Format('  p.LenCount:    %d', [p^.iLenCount]));
end;

var
  bMethod: Byte;
  s, s2: String;
begin
  WriteLN('Welche Methode soll für den Typecast verwendet werden (1-3)?');
  ReadLN(bMethod);
  if not (bMethod in [1..3]) then
  begin
    WriteLN('Ungültige Eingabe');
    ReadLN;
    Exit;
  end;

  WriteLN;
  WriteLN('Der Variable "s" wird ein Wert zugewiesen');
  WriteLN('  s := ''Das ist ein Buffer für GetWindowsDirectory''');
  s := '''Das ist ein Buffer für GetWindowsDirectory''';
  WriteLN;

  WriteLn('Der eingegebene Text wird einer zweiten Variable zugewiesen');
  WriteLN('  s2 := s;');
  s2 := s;

  WriteLN;
  WriteLN('Inhalt von s:');
  ShowStringInfo(s);
  WriteLN(Format('  Pointer(s):    0x%p', [Pointer(s)]));
  WriteLN(Format('  @s:            0x%p', [@s]));
  WriteLN;

  WriteLn('Inhalt von s2:');
  ShowStringInfo(s2);
  WriteLN(Format('  Pointer(s2):   0x%p', [Pointer(s2)]));
  WriteLN(Format('  @s2:           0x%p', [@s2]));
  WriteLN;

  WriteLN('Das Windows-Verzeichnis wird nun in die Variable "s" eingelesen...');
  case bMethod of
    1 :
      begin
        WriteLN('  GetWindowsDirectory(PChar(s), Length(s));');
        GetWindowsDirectory(PChar(s), Length(s));
      end;

    2 :
      begin
        WriteLN('  GetWindowsDirectory(@s[1], Length(s));');
        GetWindowsDirectory(@s[1], Length(s));
      end;

    3 :
      begin
        WriteLN('  GetWindowsDirectory(Pointer(s), Length(s));');
        GetWindowsDirectory(Pointer(s), Length(s));
      end;
  end;

  WriteLN;
  WriteLn('Inhalt von s:');
  ShowStringInfo(s);
  WriteLN(Format('  Pointer(s):    0x%p', [Pointer(s)]));
  WriteLN(Format('  @s:            0x%p', [@s]));
  WriteLN;

  WriteLn('Inhalt von s2:');
  ShowStringInfo(s2);
  WriteLN(Format('  Pointer(s2):   0x%p', [Pointer(s2)]));
  WriteLN(Format('  @s2:           0x%p', [@s2]));
  WriteLN;

  ReadLN;  
end.

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate