Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Need help with creating Class

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
mikepj
Asked:
mikepj
  • 3
  • 2
1 Solution
 
viktornetCommented:
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
 
mikepjAuthor Commented:
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
 
viktornetCommented:
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
 
viktornetCommented:
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
 
mikepjAuthor Commented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now