Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.45 KB | None | 0 0
  1. procedure TForm2.FormularNeu1Click(Sender: TObject);
  2. var
  3.   FileStream: TFileStream;
  4.   ss:  ansistring;
  5.   tc: TComponent;
  6.   roots: integer;
  7.   rootstr: String;
  8.  
  9.   function ComponentToString(Component: TComponent): string;
  10.   var
  11.     BinStream:TMemoryStream;
  12.     StrStream: TStringStream;
  13.     s: string;
  14.   begin
  15.     BinStream := TMemoryStream.Create;
  16.     try
  17.       StrStream := TStringStream.Create(s);
  18.       try
  19.         BinStream.WriteComponent(Component);
  20.         BinStream.Seek(0, soFromBeginning);
  21.         ObjectBinaryToText(BinStream, StrStream);
  22.         StrStream.Seek(0, soFromBeginning);
  23.         Result := StrStream.DataString;
  24.       finally
  25.         StrStream.Free;
  26.       end;
  27.     finally
  28.       BinStream.Free
  29.     end;
  30.   end;
  31.   function GetParentRoot(p: TControl): TControl;
  32.   begin
  33.     if twincontrol(p).ClassName = 'TForm' then
  34.     begin
  35.       result := p;
  36.     end else
  37.     begin
  38.       inc(roots);
  39.       rootstr := rootstr + '.' + twincontrol(p).Name;
  40.       result := GetParentRoot(TWinControl(p).Parent);
  41.     end;
  42.   end;
  43.   function ReadObjects: String;
  44.   var
  45.     FileStream: TFileStream;
  46.     R: TMyReader;
  47.     s: String;
  48.     i,i2: Integer;
  49.   begin
  50.     result := '';
  51.     try
  52.       FileStream := TFileStream.Create('test.dta',fmOpenReadWrite);
  53.       try
  54.         R  := TMyReader.Create(FileStream, 1024);
  55.         s  := 'TForm';
  56.         tc := TComponentClass(FindClass(s)).Create(nil);
  57.  
  58.         FileStream.ReadComponent(tc);
  59.         FileStream.Position := 0;
  60.  
  61.         for i := 0 to twincontrol(tc).ComponentCount-1 do
  62.         begin
  63.           rootstr := rootstr + 'this.';
  64.           if tc.Components[i].ClassName = 'TPanel' then
  65.           begin
  66.             roots := 0;
  67.             GetParentRoot(twincontrol(tc.Components[i]));
  68.             rootstr := rootstr + #10;
  69.  
  70.             //showmessage(inttostr(roots));
  71.             //showmessage(TWinControl(tc.components[i]).parent.ClassName);
  72.             //showmessage(twincontrol(tc.components[i]).Name);
  73.  
  74.             //for i2 := 0 to
  75.             begin
  76. //              result := result + '.';
  77. //              result := result + twincontrol(tc.components[i]).Name;
  78.             end;
  79.           end;
  80.         end
  81.       finally
  82.         FileStream.Free;
  83.       end;
  84.     except
  85.       on E : Exception do
  86.       begin
  87.         ShowMessage('Exception class name = '+E.ClassName);
  88.         ShowMessage('Exception message = '+E.Message);
  89.       end;
  90.     end;
  91.  
  92.     result := rootstr;
  93.   end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement