Solved

assigning properties of component

Posted on 2000-03-18
10
244 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
update joined tables 2 74
MS Access from Delphi 31 102
Firemonkey BASS_Init into a thread 17 84
File Downloader in Multi threading , Measure Download Speed and progress 9 45
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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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