Autor Beitrag
mb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 185



BeitragVerfasst: Sa 24.01.04 15:56 
Hallo!

Ist es irgendwie einfach möglich, eine Form aus einer laufenden Anwendung heraus im DFM-Text-Format zu speichern?

_________________
Gruß,
MB
mazias
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Do 29.01.04 14:22 
ja, das geht!

guck dir mal die beiden Routinen hier an, ComponenttoFile speichert eine Komponente (also auche eine Form) in Textform ab. FileToComponent läd es wieder.
Aber sei Vorsichtig wenn du komplette Formulare zur Laufzeit reinladen willst: wahrscheinlich geht es nicht, du musst dann vorher erst alle Komponenten löschen -> kann knifflig werden.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
procedure ComponentToFile(Component: TComponent; filename: string);
var
  BinStream : TMemoryStream;
  StrStream : TStringStream;
  FileStream: Tfilestream;
  s: string;
begin
  BinStream := TMemoryStream.Create;
  try
    StrStream := TStringStream.Create(s);
    try
      BinStream.WriteComponent(Component);
      BinStream.Seek(0, soFromBeginning);
      ObjectBinaryToText(BinStream, StrStream);
      StrStream.Seek(0, soFromBeginning);
      filestream := tfilestream.Create(filename,fmCreate);
      filestream.copyfrom(strstream,0);
      filestream.Free;
    finally
      StrStream.Free;
    end;
  finally
    BinStream.Free
  end;
end;

procedure FileToComponent(filename: string; component: TComponent);
var
  StrStream:TStringStream;
  BinStream: TMemoryStream;
  filestream: tfilestream;
  s: string;
  c: integer;
begin
    BinStream := TMemoryStream.Create;
    try
      filestream := tfilestream.Create(filename,fmOpenRead);
      setlength(s,filestream.size);
      filestream.readbuffer(pointer(s)^,filestream.Size);
      StrStream := TStringStream.Create(s);
      filestream.Free;
      ObjectTextToBinary(StrStream, BinStream);
      BinStream.Seek(0, soFromBeginning);
      BinStream.ReadComponent(component);
    finally
      BinStream.Free;
    end;
    StrStream.Free;
end;


Gruß
Matze

Moderiert von user profile iconPeter Lustig: Code- durch Delphi-Tags ersetzt
mb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 185



BeitragVerfasst: Do 29.01.04 14:32 
Super, Matze! Vielen Dank. -> Gute Idee.

_________________
Gruß,
MB