Board index » delphi » Pointers to properties ?

Pointers to properties ?

HI !

Is there a way to make a pointer (preferrably Pchar) point to the
address of a .text property of Editboxes/Comboboxes/Maskeditboxes...?

Ive got a multipage(TabbedNotebook) Form with lots of Edit-Fields (170)
on there and Im trying to set up an Array of Pointers referencing each
ones Text Property. Any Ideas?

If not, is there a way to do a loop that goes through these Properties
and saves their contents into a file? (the names of the components are
NOT similar to each other!)

 

Re:Pointers to properties ?


On Thu, 27 Jun 1996 19:22:29 +0200, Chris

Quote
<stenc...@goofy.zdv.uni-mainz.de> wrote:
>Is there a way to make a pointer (preferrably Pchar) point to the
>address of a .text property of Editboxes/Comboboxes/Maskeditboxes...?

No, you generally can't have a pointer to a property.

Quote
>Ive got a multipage(TabbedNotebook) Form with lots of Edit-Fields (170)
>on there and Im trying to set up an Array of Pointers referencing each
>ones Text Property. Any Ideas?

That's impossible, but you can have an array of pointers to the
components themselves.  In fact, one already exists: accessed via the
Components property of the form.  What you can do is to cycle through
this, selecting out components which are of the right type and which
have the right page as their Parent (I think) property.

Duncan Murdoch

Re:Pointers to properties ?


Quote
> Chris <stenc...@goofy.zdv.uni-mainz.de> wrote in article

<31D2C355.2...@goofy.zdv.uni-mainz.de>...

Quote
> HI !

> Is there a way to make a pointer (preferrably Pchar) point to the
> address of a .text property of Editboxes/Comboboxes/Maskeditboxes...?

> Ive got a multipage(TabbedNotebook) Form with lots of Edit-Fields (170)
> on there and Im trying to set up an Array of Pointers referencing each
> ones Text Property. Any Ideas?

> If not, is there a way to do a loop that goes through these Properties
> and saves their contents into a file? (the names of the components are
> NOT similar to each other!)

First, that's an awful lot of entry fields which are grabbing a lot of
resources -- are you sure you can't think of another solution?  

I do not think you can create a pointer to a property.  A property is
often a method, and while you might be able to execute the method or
whatever, I don't think it will work.

However, depending on the kind of notebook you're using, you can loop over
the controls using the Controls array that comes as part of a TControl.
Also you can use ControlCount.  Every control in a container (e.g. Form,
Panel, PageControl, TabbedNotebook, etc.) will be in this array.  So you
might use this loop:

   // iterate over all controls in the container
   for i := 1 to MyNotebook.ControlCount - 1 do begin
      // Make sure it's the right type
      if Controls[ i ] is TEdit then begin
         //  You have an editbox -- do what you need to do, for example
         ShowMessage( TEdit( Controls[ i ].Text ));
         // Note Controls[ i ] returns a type TComponent, so cast to TEdit
first
      end;
   end;

Will this work?
--
 Tom Harrison
 Sublime Software  

Re:Pointers to properties ?


Thank=B4s for all the help regarding my problem, I think I worked out a=20
solution for looping through the relevant components on my form and=20
reading their text properties:

Procedure Tmyform.readalltext(Sender:TObject);

var i :integer;

Begin
 For i:=3D 0 to myform.componentcount-1 do    {c_count starts at 1!}
  Begin
   If components[i] IS TEdit THEN
       WRITELN(openedfile,TEdit(components[i]).text);
   If components[i] IS TCombobox THEN
       Writeln(openedfile,TCombobox(components[i].text);
    {..... a.s.f. for all relevant components (mind Tmemo !)....}
  End;
End;

Thanks again, CUL8ER
  Chris

Re:Pointers to properties ?


Quote
> Tom  <tom...@sublimesoft.com> wrote:
> First, that's an awful lot of entry fields which are grabbing a lot of
> resources -- are you sure you can't think of another solution?
> Hi Tom!

First of all thank you for your help on my problem!
I had figured out a way almost equivalent to your suggestion, using the
components property of my form.
But youre right, I do get the feeling that theres a few to many
ressources needed, to maintain all of those entry fields!
My application is aiming to be a stand-alone input aid, for the  remote
writing of Database Records which can be saved in a Textfile and later
be uploaded into an Informix-Online Database Server.
Unfortunately, the individual records of this database are as big as the
number of controls on my Form (170 fields or so each), that is excluding
the Text-Blob-fields (about 20) which I administer in Memo-Fields.
Considering that I have to do about 7 of these forms (with a tight
deadline dooming above me) I am struggling to find different ways to
accomplish this task.
Do you know by any chance wether its possible to use the
Delphi-Database-Access components on a remote basis, i.e. without a
Database-Connection at runtime?
Im not sure wether I should spend time in researching this or wether to
go on with my first approach to the prob.

Even if you dont find time to answer this,
thanks again for your first answer.

Bye, Chris.

Re:Pointers to properties ?


Quote
Chris <stenc...@goofy.zdv.uni-mainz.de> wrote:
>HI !
>Is there a way to make a pointer (preferrably Pchar) point to the
>address of a .text property of Editboxes/Comboboxes/Maskeditboxes...?
>Ive got a multipage(TabbedNotebook) Form with lots of Edit-Fields (170)
>on there and Im trying to set up an Array of Pointers referencing each
>ones Text Property. Any Ideas?
>If not, is there a way to do a loop that goes through these Properties
>and saves their contents into a file? (the names of the components are
>NOT similar to each other!)

ATTENTION: code written from scratch and not compiled and not tested:

procedure TFormWithALotOfEditsToSaveToATableOrWhatever.DoIt;
var
  i : Integer;
begin
  for i := 0 to ComponentCount-1 do
    if Components [i] is TEdit then
     with TEdt (Components [i]) do begin
       SaveToSomewhere (Text);
     end
end;

you cannot rely on the ordering, so you should use the TAG-Property to
ensure appropriate and correct saving of the tables and you should
adjust this procedure accordingly.

Hope this helps
Meik Weber
m.we...@public.ndh.com or
100744.3...@compuserve.com

Re:Pointers to properties ?


Quote
>Is there a way to make a pointer (preferrably Pchar) point to the
>address of a .text property of Editboxes/Comboboxes/Maskeditboxes...?

>If not, is there a way to do a loop that goes through these Properties
>and saves their contents into a file? (the names of the components are
>NOT similar to each other!)

        Properties cannot have pointers to them. Properties are not variables.

        Writing to files... Yes for published... Sometimes for others. Look into the
streaming docs for the components.

_
******************************************************************
NOTE: This software is currently in early alpha. If you notice any
problems, or RFC non-compliance, please report it to p...@pbe.com
 \------------------------------------------------------------\
  \           Chad Z. Hower  -  phoe...@pobox.com              \
   \  Phoenix Business Enterprises - p...@pbe.com - www.pbe.com  \
    \     Physically in Church Hill, TN - Logically Not Sure     \
     \------------------------------------------------------------\

Quote
>>SQUID - The ultimate 95/NT offline databasing reader

**Special Compile: 3.000A (Alpha)

Re:Pointers to properties ?


Quote
Phoenix Business Enterprises wrote:

> >Is there a way to make a pointer (preferrably Pchar) point to the
> >address of a .text property of Editboxes/Comboboxes/Maskeditboxes...?

> >If not, is there a way to do a loop that goes through these Properties
> >and saves their contents into a file? (the names of the components are
> >NOT similar to each other!)

>         Properties cannot have pointers to them. Properties are not variables.

>         Writing to files... Yes for published... Sometimes for others. Look into the
> streaming docs for the components.

> _
> ******************************************************************
> NOTE: This software is currently in early alpha. If you notice any
> problems, or RFC non-compliance, please report it to p...@pbe.com
>  \------------------------------------------------------------\
>   \           Chad Z. Hower  -  phoe...@pobox.com              \
>    \  Phoenix Business Enterprises - p...@pbe.com - www.pbe.com  \
>     \     Physically in Church Hill, TN - Logically Not Sure     \
>      \------------------------------------------------------------\
> >>SQUID - The ultimate 95/NT offline databasing reader
> **Special Compile: 3.000A (Alpha)

I can't say how Delphi does this, but in Paradox 7/win95, you can
obj.enumObjNames(raProperty) to an array, for instance, then use those
names to
reference the properties _indirectly_ in various methods and
procedures.  The indirect reference is done by putting the
array entry in parentheses, whereas a direct reference to a
property simply uses some property name.  So, obj.color references
the color property of obj.  But obj.(raProperty[i]) looks up the
property name in an array.  Thus, the actual property can vary
at runtime.  You can also reference the object indirectly with
constructions such as (obj).method() or (obj).value.

Jan Braswell

Other Threads