Solved

Need help with creating Class

Posted on 1998-10-03
5
137 Views
Last Modified: 2010-04-06
Hi,

I want to create a simple class which is not a descendant of an existing object.  I keep having syntax problems with it--it should be EASY!  I'm not creating any components--I just want to have the object handle the complexities of these tasks.

MyClass.SetMode(Mode:Integer);
MyClass.FModeType:Integer;
MyClass.CurrentModeName:String;

I think I need something like this:

Type
  MyObject=Object
      Mode:Integer;
      procedure SetMode(Mode:Integer);
      function FModeType:Integer; read FGetModeType;
      function GetModeName:String; read FGetModeName;
    end;

function MyObject.FGetModeType:Integer;
begin
  Result:=5;
end;

function MyObject.FGetModeName:Integer;
begin
  Result:=5;
end;

procedure MyObject.SetMode(Mode:Integer);
begin
  {do whatever}
end;

begin
  MyObject.SetModeType(mymode);

  MyString:=MyObject.GetModeName;
  MyInteger:=MyObject.GetModeType;
end;

Could you give me a runable example of this which will work?
The actual numerical results are not important.

Thank you for your help!
MP
0
Comment
Question by:mikepj
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1341648
Hello//////

   Type
     MyObject=Object
         Mode:Integer;
         procedure SetMode(Mode:Integer);
         function ModeType:Integer;
         function GetModeName:String;
       end;

   function MyObject.GetModeType:Integer;
   begin
     Result:=5;
   end;

   function MyObject.GetModeName:Integer;
   begin
     Result:=5;
   end;

   procedure MyObject.SetMode(Mode:Integer);
   begin
     {do whatever}
   end;

   begin
     MyObject.SetModeType(mymode);

     MyString:=MyObject.GetModeName;
     MyInteger:=MyObject.GetModeType;
   end;

Regards,
Viktor Ivanov
0
 
LVL 2

Author Comment

by:mikepj
ID: 1341649
Thank you for your reply.

I get "Invalid method reference" compiler error on
     MyObject.SetMode(whatever);

Why???  I tried creating a Public section and putting SetMode inside but that didn't help either.

Best regards,
MP



0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1341650
Why do you reject the answert and not just ask what else you need, and if I can;t asnswer it then reject.......
--------------
Type
          MyObject=Object
              Mode:Integer;
              procedure SetMode(Mode:Integer);
              function ModeType:Integer;
              function GetModeName:String;
            end;

        function MyObject.GetModeType:Integer;
        begin
          Result:=5;
        end;

        function MyObject.GetModeName:Integer;
        begin
          Result:=5;
        end;

        procedure MyObject.SetMode(nMode:Integer);
        begin
          ShowMessage('You''ve just turned to mode ' + IntToStr(nMode));
        end;
var
  MyObj : MyObject;
begin
  MyObj.Mode := 5;
  MyObj.SetModeType(MyObj.mode);
  MyString := MyObj.GetModeName;
  MyInteger:=MyObj.GetModeType;
end;

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341651
If you are trying to compile it it won't do it because you have defined thenames in deifferent way so it won't work ...here is something that will compile...I guess....
----------------

   Type
             MyObject=Object
                 Mode:Integer;
                 procedure SetMode(Mode:Integer);
                 function GetModeType:Integer;
                 function GetModeName:String;
               end;

           function MyObject.GetModeType:Integer;
           begin
             Result:=5;
           end;

           function MyObject.GetModeName:String;
           begin
             Result := 'Some Mode Name';
           end;

           procedure MyObject.SetMode(nMode:Integer);
           begin
             ShowMessage('You''ve just turned to mode ' + IntToStr(nMode));
           end;
   var
     MyObj : MyObject;
      MyString : String;
      MyInteger : Integer;
   begin
     MyObj.Mode := 3;
     MyObj.SetMode(MyObj.mode);
     MyString := MyObj.GetModeName;
     MyInteger:=MyObj.GetModeType;
   end;
------------
This is suppose to compile even though I haven't tried it.....Check it out

Regards,
Viktor Ivanov
0
 
LVL 2

Author Comment

by:mikepj
ID: 1341652
Sorry about rejecting the previous answer; it was the same error I was getting and didn't think you'd know how to solve it.

Thank you for your help with this--it is exactly what I needed.

Best regards,
MP

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now