delphi - Must I define both the forward declaration and the interface of a class in the same section? -


i have class want keep private, because use in implementation section. used class declared public in interface section.

is there way this:

unit x;  interface    type     tprivate = class;  //forward declaration      tpublic = class(tsomething)     private       fprivate: tprivate;       procedure dostuffwithfprivate;     public       //...     end;   implementation   type    tprivate = class(tobject)      procedure test;    end; 

obviously above code gives error:

[dcc32 error] unitx.pas(27): e2086 type 'tprivate' not yet defined

i don't want resort cheap tricks like:

fprivate = tobject .... procedure tpublic.dostuffwithfprivate; begin   tprivate(fprivate).test; 

is there way want without having spill tprivate's internal details in interface?

i know it's possible declare tprivate strict private sub type of tpublic, don't pollution of interface section gives.
there way keep tprivate out of interface section (as possible) whilst maintaining type safety?

as long tprivate not used anywhere in interface of tpublic besides field declaration (f.i. methods parameter type) can use local class helper achieve this.

note: fprivate not name field!

interface  type   thiddenactual = class   end;    tpublic = class   private     factual: thiddenactual;     procedure dostuffwithfprivate;   public   end;  implementation  type   tactual = class(thiddenactual)   public     procedure foo;   end;  type   tpublichelper = class helper tpublic   private     function getactual: tactual;     procedure setactual(const value: tactual);   public     property actual: tactual read getactual write setactual;   end;  procedure tactual.foo; begin end;  function tpublichelper.getactual: tactual; begin   result := factual tactual; end;  procedure tpublichelper.setactual(const value: tactual); begin   factual := value; end;  procedure tpublic.dostuffwithfprivate; begin   actual.foo; end; 

ok, merely little variance of cheap trick, alternatives? have take available, don't you?


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -