Solved

Need help with creating Class

Posted on 1998-10-03
5
148 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
[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
  • 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

734 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