Solved

Get the text representation of DFM info of a component

Posted on 1998-06-22
6
399 Views
Last Modified: 2010-04-04
I need to get the text representation of the DFM info of a single component (let's say a TQuery or a TQuickRep).
How can I do this? I need code.
Please Help.
0
Comment
Question by:Mak042298
6 Comments
 
LVL 2

Expert Comment

by:kjteng
ID: 1355281
You do not need any coding:-
use the mouse to select a component on the form
click edit copy from IDE menu
go to any editor page (eg press F12), click edit and paste
the text representation will be pasted

0
 
LVL 2

Expert Comment

by:kjteng
ID: 1355282
You do not need any coding:-
     use the mouse to select a component on the form
     click edit copy from IDE menu
     go to any editor page (eg press F12), click edit and paste
     the text representation will be pasted

Let me know if I have interpret you question incorrectly
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1355283
Here is a simple example. The resulting text is not excatly the same as the "view as text" options but most of the properties are shown. The exact difference I don't know, I think this is the best you can get. It uses the ObjectResourceToText function in the unit Classes. (The other option is ObjectBinaryToText you have to save using WriteComponent then).

*** Start of code

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  strIn, strOut : TMemoryStream;
begin
  strIn:=TMemoryStream.Create;
  strOut:=TMemoryStream.Create;
  try
    strIn.WriteComponentRes('',Form1);
    strIn.Position := 0;
    ObjectResourceToText(strIn,strOut);
    strOut.Position:=0;
    Memo1.Lines.LoadFromStream(strOut);
  finally
    strIn.Free;
    strOut.Free;
  end;
end;

end.

*** end of code

*** start of code

object Form1: TForm1
  Left = 200
  Top = 108
  Width = 435
  Height = 300
  Caption = 'Form1'
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 0
    Top = 8
    Width = 425
    Height = 169
    Lines.Strings = (
      'Memo1')
    TabOrder = 0
  end
  object Button1: TButton
    Left = 176
    Top = 192
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
end

*** end of code

This code does it for the form. But you can use any component...

Just too late for the points..... grrrr...

I'll post it anyway..... :(
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:hrizal
ID: 1355284
Here, i write the function for you.


Function ReadDFM(dfmName : String) : String;
var Source,
    Destination  : TStream;
    Temp         : TStringList;
   
begin
  Source      := TFileStream.create(dfmName,fmOpenread);
  Destination := TFileStream.Create('temp$$$',fmCreate);
  // add more point please ...
  ObjectResourceToText(Source,Destination);
  Source.Free;
  Destination.Free;
  temp := TStringList.Create;
  temp.LoadFromFile('temp$$$');
  result := temp.text;
  free.temp;
end;

0
 

Author Comment

by:Mak042298
ID: 1355285
OK, Jacco your solution worked just as I expected. Send it again and  I'll give you an A.
Sorry kjteng, but your solution is very simply.
0
 

Accepted Solution

by:
keksperte earned 100 total points
ID: 1355286
Why not have a look to the gifts?

I wish to say:

there in the DELPI\BIN Path, ther is a little program called CONVERT.EXE
I please you to try it. Because:

Convert Unit1.DFM  gives you a Unit1.Txt and   ( you can use masking as *.dfm)
Convert Unit1.TXT   makes a new/old Form Unit1.DFM
!!! It overwrites !!!

Its nice, isn't it ?

Be heapy. A Kekspert.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now