Solved

assigning properties of component

Posted on 2000-03-18
10
242 Views
Last Modified: 2010-04-04
Dear experts!

I get a problem. The problem is that I do not know how to associate property of component and text value of property name.

For example. Let's suppose I have a text file. The text file look like this:
....
left = 100
top = 200
caption = "some caption"
...

Then I have a component (abstract component). How to assign values to property of the component from that text file?

It must be:

procedure AssignProp(aComp : TComponent; aPropName : string; aValue : Variant);
begin
  // implementation wanted!!!!
end;

PS:
------------
I know how to save/load a component to/from stream in the text format, it's unusable for me.
------------
if aPropName = 'LEFT' then aComp.Left := aValue; // is also unusable.

PPS:
I'm not hurry up.
0
Comment
Question by:ITugay
10 Comments
 

Expert Comment

by:HamidHossain
ID: 2631022
You can use TStringList


var
  List : TStringList;
begin
  try
    List := TStringList.Create;
    List.LoadFromFile('MyText.txt');
    aComp.Left := StrToInt(List.Values['Left']);
    ...
    ...
  finally
    List.Free;
  end;
end;
0
 

Expert Comment

by:HamidHossain
ID: 2631025
remember that

--- MyText ---
Fire=12
Caption=Welcome to my component
--------------

Can be accessed by

  MyInteger := IntToStr(List.Values['Fire']);
  MyString  := List.Values['Caption'];

and so on ...

Regards,
Hamid
0
 

Expert Comment

by:HamidHossain
ID: 2631026
take care for letters case
 so 'Fire' <> 'fire'

;)
0
 

Expert Comment

by:HamidHossain
ID: 2631029
I made misstake in the second comment

it should be StrToInt

Sorry
0
 
LVL 9

Author Comment

by:ITugay
ID: 2631040
Dear Hamid!

I can manipulate with TStrings and I have some understanding about characters case. I told about  an abstract component, it mean that component may have or may NOT have a property with name "Left".

Best regards,
Igor.
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 17

Expert Comment

by:inthe
ID: 2631074
Hi
do you know about readcomponentres / writecomponentres ?
They can save a entire form full of components or just one component (as long as the components properties are published )it saves to dfm.
you can then use convert.exe (in delphi bin dir )or i can give you procedure for comversions to convert the dfm writecomponentres makes into a text file.
 
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
ID: 2631152
0
 
LVL 9

Author Comment

by:ITugay
ID: 2631179
to inthe,
Of course, I know about his ;)
Igor.

PS: To all, I will available at mondey ;-)
0
 

Expert Comment

by:carlca
ID: 2632047
If you have Delphi 5, simply include TypInfo in your uses clause and use the SetPropInfo procedure. It is used in almost the same as your AssignProp procedure. The parameters are:

(Instance: TObject;
const PropName: string;
const Value: Variant);

Cheers,
Carl
0
 
LVL 9

Author Comment

by:ITugay
ID: 2633016
Thanx to Epsylon and Carl.

Yes, "TypeInfo" is magic word what I need. I found all I need in that unit.

Thanx all.

Igor.
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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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: …
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

18 Experts available now in Live!

Get 1:1 Help Now