Solved

assigning properties of component

Posted on 2000-03-18
10
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month5 days, 13 hours left to enroll

626 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