BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Define a property to pass an array

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
Frank
Guest





PostPosted: Wed Dec 24, 2003 2:12 pm    Post subject: Define a property to pass an array Reply with quote



I need to pass a value from one Form to a second Form called by the first. I
implemented a suggestion to define a property like the following:
property Fullpath: string read fFullpath write fFullpath;

In the calling Form, I initialize the Fullpath variable with the value I
need, and the called Form uses it.
This is ok for strings, but I need to pass a dynamic array. Can I do this
and how do I define a correct property ?


Back to top
J French
Guest





PostPosted: Wed Dec 24, 2003 3:47 pm    Post subject: Re: Define a property to pass an array Reply with quote



On Wed, 24 Dec 2003 14:12:06 GMT, "Frank" <iuesei (AT) virgilio (DOT) it> wrote:

Quote:
I need to pass a value from one Form to a second Form called by the first. I
implemented a suggestion to define a property like the following:
property Fullpath: string read fFullpath write fFullpath;

In the calling Form, I initialize the Fullpath variable with the value I
need, and the called Form uses it.
This is ok for strings, but I need to pass a dynamic array. Can I do this
and how do I define a correct property ?

In my version of Delphi (D4 Pro)
- this is something that is sadly lacking

The simple hack is to create your own Type - TDynStrArray

It would be nice if it were standardized

(You can pass Arrays that are Dynamic or not, but SetLength() is no
use within the Procedure/Function)

Back to top
Rick Carter
Guest





PostPosted: Wed Dec 24, 2003 11:51 pm    Post subject: Re: Define a property to pass an array Reply with quote



"Frank" <iuesei (AT) virgilio (DOT) it> wrote

Quote:
This is ok for strings, but I need to pass a dynamic array. Can I do this
and how do I define a correct property ?

See online help for Variant Arrays.
If you're using Delphi 6, download and apply the patches first before doing
any serious work with variants.

Rick Carter
Chair, Paradox/Delphi SIG, Cincinnati PC Users Group

Back to top
VBDis
Guest





PostPosted: Sat Dec 27, 2003 10:15 pm    Post subject: Re: Define a property to pass an array Reply with quote

Im Artikel <W8hGb.4423$_P.141622 (AT) news4 (DOT) tin.it>, "Frank" <iuesei (AT) virgilio (DOT) it>
schreibt:

Quote:
In the calling Form, I initialize the Fullpath variable with the value I
need, and the called Form uses it.
This is ok for strings, but I need to pass a dynamic array. Can I do this
and how do I define a correct property ?

A TStringList (or TList) type might be the simplest solution.

DoDi

Back to top
Frank
Guest





PostPosted: Sun Dec 28, 2003 10:27 am    Post subject: Re: Define a property to pass an array Reply with quote

This could be a good idea. But how I define the property for a TStringList
if I did the following for a string?
property Fullpath: string read fFullpath write fFullpath;

"VBDis" <vbdis (AT) aol (DOT) com> ha scritto nel messaggio
news:20031227171505.12631.00003744 (AT) mb-m28 (DOT) aol.com...
Quote:
Im Artikel <W8hGb.4423$_P.141622 (AT) news4 (DOT) tin.it>, "Frank"
[email]iuesei (AT) virgilio (DOT) it[/email]
schreibt:

In the calling Form, I initialize the Fullpath variable with the value I
need, and the called Form uses it.
This is ok for strings, but I need to pass a dynamic array. Can I do this
and how do I define a correct property ?

A TStringList (or TList) type might be the simplest solution.

DoDi



Back to top
Nicholas Sherlock
Guest





PostPosted: Sun Dec 28, 2003 11:05 pm    Post subject: Re: Define a property to pass an array Reply with quote

var ffullpath:tstringlist;

property fullpath:tstringlist read ffullpath write ffullpath;

Cheers,
Nicholas Sherlock

Frank wrote:
Quote:
This could be a good idea. But how I define the property for a
TStringList if I did the following for a string?
property Fullpath: string read fFullpath write fFullpath;

"VBDis" <vbdis (AT) aol (DOT) com> ha scritto nel messaggio
news:20031227171505.12631.00003744 (AT) mb-m28 (DOT) aol.com...
Im Artikel <W8hGb.4423$_P.141622 (AT) news4 (DOT) tin.it>, "Frank"
[email]iuesei (AT) virgilio (DOT) it[/email]> schreibt:

In the calling Form, I initialize the Fullpath variable with the
value I need, and the called Form uses it.
This is ok for strings, but I need to pass a dynamic array. Can I
do this and how do I define a correct property ?

A TStringList (or TList) type might be the simplest solution.

DoDi



Back to top
Bruce Roberts
Guest





PostPosted: Mon Dec 29, 2003 5:51 am    Post subject: Re: Define a property to pass an array Reply with quote


"J French" <erewhon (AT) nowhere (DOT) com> wrote

Quote:
On Wed, 24 Dec 2003 14:12:06 GMT, "Frank" <iuesei (AT) virgilio (DOT) it> wrote:

I need to pass a value from one Form to a second Form called by the
first. I
implemented a suggestion to define a property like the following:
property Fullpath: string read fFullpath write fFullpath;

In the calling Form, I initialize the Fullpath variable with the value I
need, and the called Form uses it.
This is ok for strings, but I need to pass a dynamic array. Can I do this
and how do I define a correct property ?

In my version of Delphi (D4 Pro)
- this is something that is sadly lacking

The simple hack is to create your own Type - TDynStrArray

Its not a hack, its simply the way Delphi works because of its strong
typing.

Quote:
It would be nice if it were standardized

I'm at a loss by what you mean by "standardized". Declaring a type is the
standard way of doing things. It certainly prevents mistakes that can occur
when one attempts to assign a value of a different type which just happens
to have the same base type.

Quote:
(You can pass Arrays that are Dynamic or not, but SetLength() is no
use within the Procedure/Function)

This is not really correct. One can pass open array parameters. In which
case one cannot alter the length of the formal parameter. One can also pass
dynamic array types. In which case, presuming that the parameter is passed
by reference, one can alter their length. The confusion is that the syntax
for an open array parameter is the same for the declaration of a dynamic
array.

Type tDynStrArray = array of string;

is a dynamic array. While

procedure foo (x : array of string);

declares x as an open array parameter. Not the same thing.

But one can do

procedure foo (var x : tDynStrArray);

and then, in the body of foo do

SetLength (x, 12);

without any problem. What the compiler insists on is that the author be
explicit about the types of data being referenced and passed around. For
those used to less rigorous languages this may seem, at first, to be quite a
burden. Work on any significant project for a while, especially one
involving more than one author, to appreciate how truly beneficial this
strong typing is.



Back to top
J French
Guest





PostPosted: Mon Dec 29, 2003 9:28 am    Post subject: Re: Define a property to pass an array Reply with quote

On Mon, 29 Dec 2003 00:51:14 -0500, "Bruce Roberts"
<ber (AT) bounceitattcanada (DOT) xnet> wrote:

Quote:

"J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:3fe9b3d3.32160879 (AT) news (DOT) btclick.com...
On Wed, 24 Dec 2003 14:12:06 GMT, "Frank" <iuesei (AT) virgilio (DOT) it> wrote:

I need to pass a value from one Form to a second Form called by the
first. I
implemented a suggestion to define a property like the following:
property Fullpath: string read fFullpath write fFullpath;

In the calling Form, I initialize the Fullpath variable with the value I
need, and the called Form uses it.
This is ok for strings, but I need to pass a dynamic array. Can I do this
and how do I define a correct property ?

In my version of Delphi (D4 Pro)
- this is something that is sadly lacking

The simple hack is to create your own Type - TDynStrArray

Its not a hack, its simply the way Delphi works because of its strong
typing.

It would be nice if it were standardized

I'm at a loss by what you mean by "standardized". Declaring a type is the
standard way of doing things. It certainly prevents mistakes that can occur
when one attempts to assign a value of a different type which just happens
to have the same base type.

<snip>

What I really mean is a type declared in the libraries
- so everybody used the same 'declaration'

I'm pretty keen on Strong Typing
- but also nervous about things not being consistent

Back to top
Bruce Roberts
Guest





PostPosted: Tue Dec 30, 2003 7:16 pm    Post subject: Re: Define a property to pass an array Reply with quote


"J French" <erewhon (AT) nowhere (DOT) com> wrote



Quote:
What I really mean is a type declared in the libraries
- so everybody used the same 'declaration'

It would be nice if the Help contained all of the visible type declarations
in the VCL. I've learned to check Windows, SysUtils, and other units before
defining my own generic types. The only danger, of course, is that the VCL
authors are free to alter their declarations. So one must be judicious in
their use of VCL type declarations.



Back to top
J French
Guest





PostPosted: Tue Dec 30, 2003 8:28 pm    Post subject: Re: Define a property to pass an array Reply with quote

On Tue, 30 Dec 2003 14:16:12 -0500, "Bruce Roberts"
<ber (AT) bounceitattcanada (DOT) xnet> wrote:

Quote:

"J French" <erewhon (AT) nowhere (DOT) com> wrote in message
news:3feff289.70050559 (AT) news (DOT) btclick.com...


What I really mean is a type declared in the libraries
- so everybody used the same 'declaration'

It would be nice if the Help contained all of the visible type declarations
in the VCL. I've learned to check Windows, SysUtils, and other units before
defining my own generic types. The only danger, of course, is that the VCL
authors are free to alter their declarations. So one must be judicious in
their use of VCL type declarations.

That had never occurred to me - an unpleasant thought
.... would they be so irresponsible ...

Back to top
VBDis
Guest





PostPosted: Wed Dec 31, 2003 11:44 am    Post subject: Re: Define a property to pass an array Reply with quote

Im Artikel <GeyHb.13466$VW.640170 (AT) news3 (DOT) tin.it>, "Frank" <iuesei (AT) virgilio (DOT) it>
schreibt:

Quote:
This could be a good idea. But how I define the property for a TStringList
if I did the following for a string?
property Fullpath: string read fFullpath write fFullpath;

Retype the property and fFullpath field from :string to :TStringList.

You may have to change more, e.g. destroy a previously stored list. Then you'll
have to change the property to:
property Fullpath: TStringList read fFullpath write SetFullpath;
and implement a method
procedure SetFullPath(list: TStringList);
like
begin
fFullpath.Free;
fFullpath := list;
end;

Or you may want to manage a private string list, so that SetFullPath adds the
given list to the fFullpath list. Then you'll also want a method to clear the
private list. And don't forget fFullpath := TStringList.Create in the
constructor and fFullpath.Free in the destructor.

While (dynamic) arrays are reference counted, a TStringList object must be
destroyed explicitly. Just when passing such a list to another procedure it's
good style to define, who has the ownership of that object, and who
consequently is responsible for destroying the object, when it's no more used.

DoDi

Back to top
Bruce Roberts
Guest





PostPosted: Thu Jan 01, 2004 6:00 am    Post subject: Re: Define a property to pass an array Reply with quote


"J French" <erewhon (AT) nowhere (DOT) com> wrote


Quote:
That had never occurred to me - an unpleasant thought
... would they be so irresponsible ...

Unlikely, but it does happen. IIRC a number of base types changed to
Cardinal with D5. Shouldn't have caused any problem with code using derived
types, but one never knows Smile.



Back to top
VBDis
Guest





PostPosted: Sat Jan 03, 2004 5:04 am    Post subject: Re: Define a property to pass an array Reply with quote

Im Artikel <3feff289.70050559 (AT) news (DOT) btclick.com>, [email]erewhon (AT) nowhere (DOT) com[/email] (J French)
schreibt:

Quote:
I'm pretty keen on Strong Typing
- but also nervous about things not being consistent

I often miss predefined integer standard types, signed and unsigned, with a
specific byte count, usable when reading binary records from files, and in
other places. Many people define such types, but unfortunately everybody uses a
different naming convention. The current Delphi types, like SmallInt and
ShortInt, are more a source of confusion than a clarification of the actual
size of such types.

DoDi

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.