Solved

Using Object instead of Class generates compiler error

Posted on 2001-07-19
6
297 Views
Last Modified: 2013-11-23
Hi everyone.

To prevent me from having all the methods of the TObject class while having almost all the advantages of a class, I started to use the Object keyword (to replace Class). Everything worked fine until I started to use them with indexed properties. Doing so forced me to do something like : Result (Object) := MyObject. The problem is that it generates a compiler error with delphi 5 (ex.: error #12345 You should not receive this message...contact Borland...blablabla).

The help files says that Object is supported only for backward compatibility.

 Any clue on why it was leaved, what replaced it and how I can make this work?

GunDamn
0
Comment
Question by:comptebidon81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6298290
Hi comptebidon81,

here is small sample. It shows how to create new object, put it into list and then get some it's property by index from the list.

-----
Igor

type
// your object declaration
  PMyObject = ^TMyObject;
  TMyObject = object
  private
    FX: Integer;
    FY: Integer;

    procedure SetX(Value: Integer);
    procedure SetY(Value: Integer);
  public
    property X: Integer read FX write SetX;
    property Y: Integer read FY write SetY;
  end;

// list that keep your objects
  TMyList = class(TList)
  private
    function GetMyObject(I: Integer): TMyObject;
  public
    property MyObjects[Index: Integer]: TMyObject read GetMyObject;
  end;

implementation

procedure TMyObject.SetX(Value: Integer);
begin
  FX := Value;
end;

procedure TMyObject.SetY(Value: Integer);
begin
  FY := Value;
end;

function TMyList.GetMyObject(I: Integer): TMyObject;
begin
  Result := PMyObject(Items[I])^;
end;

.....

var
  L: TMyList;
  M: PMyObject;
begin
  L := TMyList.Create;

  New(M);
  M.X := 128;
  M.Y := 111;
  L.Add(M);

  New(M);
  M.X := 500;
  M.Y := 555;
  L.Add(M);

  Caption := IntToStr(L.MyObjects[0].X);

end;

0
 

Author Comment

by:comptebidon81
ID: 6298486
Thats not bad, but its not what I want.

I already build my Class. It works perfectly except for all the methods that I don't want to see. But I think it is better than having to work with a List. This class will be used by other and I have to make it simple. With my method, the user will have only one object to declare and create.

I don't know if it is possible to do better, but I'd like to try. I would also like to know what happened with "object"

Thanks anyway, Igor
GunDamn
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6298558
Hi comptebidon81,

now I'm living the office, but you can send me the part of your code that doesn't work. I will take a look tomorrow.

-----
Igor.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:comptebidon81
ID: 6302887
My code works fine. Its the compiler that has a bug. It stops at the end of a procedure because with the message [Fatal Error] BindingData.pas(1089): Internal error: C10652
This is the line that generates it:
        Result := rMyObject;
were Result and rMyObject are declared with the keyword object (similar to class(Tobject) but with no properties or method)

That is why I wanted to know what happened with this "object" thing.

Thanks again
GunDamn
0
 
LVL 9

Accepted Solution

by:
ITugay earned 75 total points
ID: 6304487
Hi GunDamn,

Ok, seems it's really compiller error. I can't reproduce it, my compiller works fine.
Anyway, it should be no problem to use pure objects.

-----
Igor
0
 

Author Comment

by:comptebidon81
ID: 7469462
It took about a year, but I finnally closed this question!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question