 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Frank Guest
|
Posted: Wed Dec 24, 2003 2:12 pm Post subject: Define a property to pass an array |
|
|
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
|
Posted: Wed Dec 24, 2003 3:47 pm Post subject: Re: Define a property to pass an array |
|
|
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
|
Posted: Wed Dec 24, 2003 11:51 pm Post subject: Re: Define a property to pass an array |
|
|
"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
|
Posted: Sat Dec 27, 2003 10:15 pm Post subject: Re: Define a property to pass an array |
|
|
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
|
Posted: Sun Dec 28, 2003 10:27 am Post subject: Re: Define a property to pass an array |
|
|
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
|
Posted: Sun Dec 28, 2003 11:05 pm Post subject: Re: Define a property to pass an array |
|
|
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
|
Posted: Mon Dec 29, 2003 5:51 am Post subject: Re: Define a property to pass an array |
|
|
"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
|
Posted: Mon Dec 29, 2003 9:28 am Post subject: Re: Define a property to pass an array |
|
|
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
|
Posted: Tue Dec 30, 2003 7:16 pm Post subject: Re: Define a property to pass an array |
|
|
"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
|
Posted: Tue Dec 30, 2003 8:28 pm Post subject: Re: Define a property to pass an array |
|
|
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
|
Posted: Wed Dec 31, 2003 11:44 am Post subject: Re: Define a property to pass an array |
|
|
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
|
Posted: Thu Jan 01, 2004 6:00 am Post subject: Re: Define a property to pass an array |
|
|
"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 .
|
|
| Back to top |
|
 |
VBDis Guest
|
Posted: Sat Jan 03, 2004 5:04 am Post subject: Re: Define a property to pass an array |
|
|
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 |
|
 |
|
|
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
|
|