Solved

Need help with creating Class

Posted on 1998-10-03
5
139 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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