Closed maxkleiner closed 1 year ago
Or you put just methods in a class without specific constructor: procedure SIRegister_TAzuliaStrings(CL: TPSPascalCompiler); begin //with RegClassS(CL,'TOBJECT', 'TAzuliaStrings') do with CL.AddClassN(CL.FindClass('TOBJECT'),'TAzuliaStrings') do begin Function NPos( C : Char; S : string; N : Byte) : Byte'); Function IntToRoman( Value : Longint) : string'); Function RomanToInt( const S : string) : Longint'); Function GetDirFromStr( DirectoryString : string; IndexFromRight : integer) : string'); Function RemoveChars( InputString : string; CharToRemove : Char) : string'); Function GetStringFromGarbage( InputString : string; Index : integer) : string'); Function SplitupWithGarbage( InputString : string; CommonSplitter : char) : string'); Function GetCount( Character : char; InputString : string) : integer'); Function RemoveTrailingChars( StringToRemoveFrom : string; Trailer : char) : string'); end; end;
Answer9:
No, maXbox4 does not have static methods.
One rule-of-thumb: ask yourself "Does it make sense to call this method, even if no object has been constructed yet?" If so, it should definitely be static.
So in a class Car you might have a method:
double convertMpgToKpl(double mpg)
...which would be static, because one might want to know what 35mpg converts to, even if nobody has ever built a Car. But this method (which sets the efficiency of one particular Car):
void setMileage(double mpg)
...can't be static since it's inconceivable to call the method before any Car has been constructed.
Or a bitmap instead of a car with a utility function:
FPicRed:= TBitMap.Create; FPicled.LoadFromResourcename(Hinstance, 'yellow1'); FPicRed.LoadFromFile(Exepath+'\examples\images\red1.bmp');
Static method calls are made directly on the class and are not callable on instances of the class. Static methods are often used to create utility functions.