Board index » delphi » String[X] as Object Property ?

String[X] as Object Property ?

I have a quick question.

        Can I have a property of type string[5].  When I try to define one as:
                property MyString: String[x] Read FString Write FString;
        I get an error at the '[' saying "Read, Write or Index expected . .
.".
        When I tried:
                property MyString: String Read FString Write FString;
        I got an error about incompatible types ShortString and String;
        And
                property MyString: ShortString Read FString Write FString
        gave a simple error of incompatible types.
        Using
                property MyString: String Read FString Write SetFString
        also gave me trouble.
Am I doing something wrong, or am I just barking up the wrong tree?
Thanks for any help.

--
Rob Tanner B.E., B.Sc.
Network Adminstrator/Programmer
Dasher Transportation Services, Inc.
2318 Northridge Dr.
Saskatoon, SK
S7L 1B9
Canada

Phone: (306) 665-3113
Fax    : (306) 665-5857
email  : rtan...@webster.sk.ca

 

Re:String[X] as Object Property ?


Quote
Robby Tanner wrote:

> I have a quick question.

>         Can I have a property of type string[5].  When I try to define one as:
>                 property MyString: String[x] Read FString Write FString;
>         I get an error at the '[' saying "Read, Write or Index expected . .
> .".
>         When I tried:[...]

        It's getting confused because "string[5]" is more a type definition
than the name of a type. All you gotta do is give the type a name and use that:

type

     String5 = string[5];

     THmm = class
      FString: string5;
      property MyString: String5 Read FString Write FString;
     end;

--
David Ullrich

sig.txt not found

Re:String[X] as Object Property ?


Hi Robby,

Quote
> Can I have a property of type string[5].

The usual way would be something like this:

  type TStr5 = string[5];

       MyClass = class
       private
         FMyString: TStr5;
       published
         property MyString: TStr5 read FMyString write FMyString;
       end;

Not sure whether Delphi's default property editor supports that type
though.

Cheers!                                         - Jon -

Re:String[X] as Object Property ?


type  String5        = String[5];

var
  FString : String5;
.
.
.

property MyString : String5 read FString write FString;

Sven

Quote
> I have a quick question.

>         Can I have a property of type string[5].  When I try to define
> one as:
>                 property MyString: String[x] Read FString Write
> FString;
>         I get an error at the '[' saying "Read, Write or Index
> expected . .
> .".
>         When I tried:
>                 property MyString: String Read FString Write FString;
>         I got an error about incompatible types ShortString and
> String;
>         And
>                 property MyString: ShortString Read FString Write
> FString
>         gave a simple error of incompatible types.
>         Using
>                 property MyString: String Read FString Write
> SetFString
>         also gave me trouble.
> Am I doing something wrong, or am I just barking up the wrong tree?
> Thanks for any help.

> --
> Rob Tanner B.E., B.Sc.
> Network Adminstrator/Programmer
> Dasher Transportation Services, Inc.
> 2318 Northridge Dr.
> Saskatoon, SK
> S7L 1B9
> Canada

> Phone: (306) 665-3113
> Fax    : (306) 665-5857
> email  : rtan...@webster.sk.ca

Re:String[X] as Object Property ?


define a new type!
eg

Type

Ts5 = String[5];

TMyObj = class
private
  fString : Ts5;
published
  property Mystring:Ts5 read Fstring write FString;
end;

In article <01bcda7b$62166a40$45130b0b@chamberlin>, Robby Tanner
<rtan...@webster.sk.ca> writes

Quote
>I have a quick question.

>       Can I have a property of type string[5].  When I try to define one as:
>               property MyString: String[x] Read FString Write FString;
>       I get an error at the '[' saying "Read, Write or Index expected . .
>.".
>       When I tried:
>               property MyString: String Read FString Write FString;
>       I got an error about incompatible types ShortString and String;
>       And
>               property MyString: ShortString Read FString Write FString
>       gave a simple error of incompatible types.
>       Using
>               property MyString: String Read FString Write SetFString
>       also gave me trouble.
>Am I doing something wrong, or am I just barking up the wrong tree?
>Thanks for any help.

Kind Regards
Claire, c...@HallworthHome.demon.co.uk

Re:String[X] as Object Property ?


On 27 Oct 1997 20:34:13 GMT, Anselm.Pe...@t-online.de (Anselm Peter)
wrote:

Quote
>On 16 Oct 97 20:50:52 GMT, "Robby Tanner" <rtan...@webster.sk.ca>
>wrote:

>>I have a quick question.

>>        Can I have a property of type string[5].  When I try to define one as:
>>                property MyString: String[x] Read FString Write FString;

Define the String[x] as a type in itself, then use the type in the
property

i.e.

type    tMyString = string[5];

property TheString : tMyString read fString write fString;

Other Threads