Использовать в Delphi средство проверки типов для ваших собственных типов данных
Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch
{
Delphi pruft die Typen der ubergebenen Variablen fur entsprechende
var Parameter einer Prozedure / Funtion anhand der gefuhrten Typen.
Dabei wird unterschieden zwischen strenge und schwache Typendeklarationen.
Das kann man ausnutzen, um bestimmte Bedingungen zu kreieren, die
beim Programmieren respektiert sein mussen: Delphi wird u.U. einen
Compiler-Fehler produzieren.
}
{
Delphi checks the type of variables you pass in a procedure or a function
call for declared var parameters.
It makes a difference if you make a strong or weak type declaration.
You can use this casuality to create a design time proofing rule, proofing
the code at design time. Delphi won't compile a code part if it's
"strong checked".
}
type
// Strenge Prufung wird veranlasst
// Strong checking will be operated
TCheckedIniFileNameType = type
string;
// Schwache Prufung bei dieser Typ-Deklaration
// Weak checking for this type declaration
TSimpleIniFileNameType = string;
{ This will be strong checked }
procedure CheckedTypeProcedure(var IniFileName: TCheckedIniFileNameType);
begin
ShowMessage(IniFileName);
end;
{ This will be less strong checked }
procedure SimpleTypeProcedure(var IniFileName: TSimpleIniFileNameType);
begin
ShowMessage(IniFileName);
end;
{ Weakest form of checking }
procedure NoTypeProcedure(var IniFileName: string);
begin
ShowMessage(IniFileName);
end;
procedure TForm4.Button1Click(Sender: TObject);
var
StringOnly: string;
SimpleIniFileName: TSimpleIniFileNameType;
CheckedIniFileName: TCheckedIniFileNameType;
begin
StringOnly := 'C:\TEST.TXT';
SimpleIniFileName := 'C:\TEST.TXT';
CheckedIniFileName := 'C:\TEST.TXT';
// This will compile...
CheckedTypeProcedure(CheckedIniFileName);
SimpleTypeProcedure(SimpleIniFileName);
SimpleTypeProcedure(StringOnly);
NoTypeProcedure(StringOnly);
NoTypeProcedure(SimpleIniFileName);
// This will not...
CheckedTypeProcedure(SimpleIniFileName);
CheckedTypeProcedure(StringOnly);
SimpleTypeProcedure(CheckedIniFileName);
NoTypeProcedure(CheckedIniFileName);
end;
|