Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

some basic but no mannul problem

Status
Not open for further replies.

SonicChen

Programmer
Feb 14, 2004
62
CN
1. default modifier in class memeber without apparent declation is public or puhlished?
2. i see the declaration like this
Code:
 procedure A(var B);
B has no type indentity. what's the B or any type?
3. i see the definition of one class method
Code:
class procedure A.B(P: A);
begin
  if Self<>P then ...
end;
in my comprehension i look class precodure B as the static method of the class A. so complier should not carry self pointer to it.
i can't find the mannul about these questions.
thanks a lot to anyone reply.


way to gold shines more than gold
 
1. Public

2. See "Untyped parameters" in Delphi help
In my Delphi it is not indexed properly. Try:
- Procedures and functions
- See also
- Parameters overview
- See also
- Untyped parameters

3. See "Class methods" in Delphi help
 

Sonic:

Class methods are a very subtle issue. Don't get ashamed if you can't understand it from start.

IMHO, it is one of those things you can forget until you need it; trying to understand why a class method is needed without having a specific scenario to apply it is usually hard (and worthless).

If at some point you need to operate upon a class without having/using an instance object, you are ready to approach to class methods.

buho (A).
 
i know it's easy to control the number of instance of class in C# for C#'s static method and static field.
we can force unique instance of a class in application's global site.
but i can only use unit global variable and class method in delphi to implement it.
that's just the scenario i encountered.
any better method?

way to gold shines more than gold
 
I'm not totally sure what you are trying to do.

Its always a recommendation to use Delphi techniques when programming in Delphi, C# techniques in C#, Cobal techniques in Cobal, etc.

Here are three Delphi techniques, the first two are commonly used, the third is not.

1. Single global instance created on demand. See Printer function in VCL Printers.pas.

Code:
function Printer: TPrinter;

implementation

var
  FPrinter: TPrinter = nil;

function Printer: TPrinter;
begin
  if FPrinter = nil then FPrinter := TPrinter.Create;
  Result := FPrinter;
end;

initialization

finalization
  FPrinter.Free;  {Frees the single object, if it were created on close of application}

end.

2. COM with its inbuilt reference counting.

Subclass your object from TInterfacedObject.

Other possibilities with COM too. COM in Delphi is a big subject and I'm going no further here.

3. Instance counting object

Code:
TInstanceCounter=class(TAnythingYouLike)
public
  constructor Create; {override?}
  destructor Destroy; override;  
  class function Instances:integer; 
end;

implementation

var
  FInstances:integer=0;

constructor TInstanceCounter.Create; {override?}
begin
  inherited Create;

  Inc(FInstances);
end;

destructor TInstanceCounter.Destroy; override;  
begin
  Dec(FInstances);

  inherited;
end;

class function TInstanceCounter.Instances:integer;
begin
  Result:=FInstances;
end;
 
yeah! it's really a very good thought.
thanks a lot.
and first of all, congratulation to buho's 2 stars


way to gold shines more than gold
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top