Author | Message |
---|
Modji Clone Posts: 2
| hi there i am from Iran please help me, i working on a program to encrypt data on direct connect protocol, it is written in delphi, pleas help my main unit calls to the second unit to return a return value, but i cant get it to work, it just will not compile. this is my code: main function:
Code: | procedure TForm1.GetRetClick(Sender: TObject); begin iRetVal := TFuncs.GetRetWithVal(6); end; | this is the start of my second class.
Code: | unit Unit2; interface type TFuncs = class function GetRetValWith(iVal: Integer): Integer; private iCent, iRotate, iTerm: Integer; end; implementation function TFuncs.GetRetValWith(iVal: Integer): Integer; begin Result := 0; case iVal of 1: Result := iVal * iCent div (iRotate div iTerm); Result := Result + Result; 2: Result := iRotate * iCent div (iVal div iTerm); 3: Result := iTerm * iCent div (iVal div iRotate); else Result := 0; end; end; end. | thank you for your time.
|
Meka][Meka Unstopable Posts: 700
| hi there modji welcome, ok...
Code: | 1: Result := iVal * iCent div (iRotate div iTerm); Result := Result + Result; | your first result has 2 lines of code, therfore you need to begin the procedural and end it. like so:
Code: | 1: begin Result := iVal * iCent div (iRotate div iTerm); Result := Result + Result; end; | so now you should have
Code: | function TFuncs.GetRetValWith(iVal: Integer): Integer; begin Result := 0; case iVal of 1: begin Result := iVal * iCent div (iRotate div iTerm); Result := Result + Result; end; 2: Result := iRotate * iCent div (iVal div iTerm); 3: Result := iTerm * iCent div (iVal div iRotate); else Result := 0; end; end; | and on your main unit, how are you creating the TFuncs? and you have named the caller incorrect to the function, am asuming you are not creating an object if it is a function unit, to call this you would simply change
Code: | iRetVal := TFuncs.GetRetWithVal(6); | to
Code: | iRetVal := TFuncs(TFuncs).GetRetValWith(6); | ; MEKA ;
|
Modji Clone Posts: 2
| thank you lots this worked very good
|
Meka][Meka Unstopable Posts: 700
| by the way u can also change
Code: | 1: begin Result := iVal * iCent div (iRotate div iTerm); Result := Result + Result; end; | to
Code: | 1: Result := (iVal * iCent div (iRotate div iTerm)) * 2; |
|
Mickey Ametuar Posts: 115
|
Quoted from Modji | ...
Code: | procedure TForm1.GetRetClick(Sender: TObject); begin iRetVal := TFuncs.GetRetWithVal(6); end; | this is the start of my second class.
Code: | unit Unit2; interface type TFuncs = class function GetRetValWith(iVal: Integer): Integer; private iCent, iRotate, iTerm: Integer; end; implementation function TFuncs.GetRetValWith(iVal: Integer): Integer; begin Result := 0; case iVal of 1: Result := iVal * iCent div (iRotate div iTerm); Result := Result + Result; 2: Result := iRotate * iCent div (iVal div iTerm); 3: Result := iTerm * iCent div (iVal div iRotate); else Result := 0; end; end; end. | | I don't really like this way of reading data from another class. Don't get me wrong. It is working somehow and maybe OK if Object Oriented Programing doesn't exist. If you would be at an OOP exam you would fail. OOP Solution: Create an instance of class (you can create even more) and you can reach the class functions via those instances. For example:
Code: | var MyFuncs1, MyFuncs2: TFuncs; //Some Instances of class ... procedure TForm1.Create(Sender: TObject); begin ... MyFuncs1 := TFuncs.Create(...); ... end; procedure TForm1.GetRetClick(Sender: TObject); begin iRetVal := MyFuncs1.GetRetWithVal(6); end; procedure TForm1.Destroy(Sender: TObject); begin ... MyFuncs1.Free; ... end; | Wow, this Syntax Highlight is cool. Great Meka ;-) Best regards
|
Meka][Meka Unstopable Posts: 700
|
Quoted from Mickey | Wow, this Syntax Highlight is cool. Great Meka ;-) | thanks, its not quite finished yet, but it does the job for now ;)
|