Einzelnen Beitrag anzeigen

Spurius

Registriert seit: 19. Aug 2003
294 Beiträge
 
Delphi 7 Professional
 
#10

Re: Record aus stream auslesen

  Alt 25. Apr 2004, 12:13
Hier ist nochmal der Code:
Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
 TTest=record
  a,b,c: String;
 end;
var
  Form1: TForm1;
  Test: TTest;
  TestStream: TMemoryStream;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 Test.a := 'a';
 Test.b := 'b';
 Test.c := 'c';
 TestStream := TMemoryStream.Create;
 TestStream.Write(Test,sizeof(Test));
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 TestStream.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
Var Test2: TTest;
begin
  TestStream.Position := 0;
  TestStream.Read(Test2, SizeOf(TTest));
  label1.Caption := test2.b;
end;

end.
  Mit Zitat antworten Zitat