Solved

Need help with creating Class

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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