COM & Arrays

Hi everyone...

I used the Type-Library editor to create simple record, which includes two widestrings. I want to use this record in an property which has an array. Normal Delphi code would look like this:

property Attachments[Nr : Integer] : RAttachment read GetAttachments write SetAttachments;

How can I do this?

Regards, Jonny...
jonnyfiveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hi Jonny,

I have no glue so I cannot help you but I would like to know this myself.

Ciao, Mike

PS: I it at all allowed to have array properties in COM objects?
0
LischkeCommented:
Shouldn't that read "I have no clue..." ? (not my native language, sorry :-)).

Ciao, Mike
0
MadshiCommented:
Hmm... Can't you compile it the way you wrote it in your question? What does the compiler say? Perhaps I didn't understand the question?   :-))

Regards, Madshi.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

JaymolCommented:
I don't think you can have an array for a property.

John.
0
MadshiCommented:
Please show us the record definition...
0
LischkeCommented:
Actually, you can have an array-like property in Delphi comps like:

TMyComp = class
private
  FTest: array[0..10] of PRec;
  function GetTest(Index: Integer): PRec;
  procedure SetTest(Index: Integer; R: PRec);
public
  property Test[Index: Integer]: PRec read GetTest write SetTest;
end;

function TMyComp.GetTest(Index: Integer): PRec;
begin
  Result := FTest[Index];
end;

procedure TMyComp.SetTest(Index: Integer; R: PRec);
begin
  FTest[Index] := R;
end;

This is like pretending there would be an array (indicated by the brackets in the property declaration) while it in reality just a special function.

Jonny, can you use this approach in the COM object too?

Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KECommented:
Does your record definition show up in the list of available types (dropdown boxes) in the type-lib editor ?

I assume that records should be passed by reference, you may need to add an asterisk (*) to the end of the definition...

Regards
0
jonnyfiveAuthor Commented:
Hi Lischke...

yes I can and just did :-) Thanks for the help...

Regards, Jonny...
0
LischkeCommented:
:-) fine, I've learned something new too...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.