Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Seltsame Includes? (https://www.delphipraxis.net/97739-seltsame-includes.html)

Phoenix 15. Aug 2007 10:31


Seltsame Includes?
 
Jetzt steh ich voll aufm Schlauch.

Folgende simple Unit in ihrem Anfangsstadium:
Delphi-Quellcode:
unit DataObjectsPLC;

interface

uses
  // Delphi / VCL Units
  SysUtils;

type
  //*** Forward declarations
  TPLCDataLayout = class;
  TPLCBit = class;


  TPLCBit = class(TObject)
  private
    FIsError: Boolean;
    FText: String;
    procedure SetIsError(const Value: Boolean);
    procedure SetText(const Value: String);
  public
    property IsError: Boolean read FIsError write SetIsError;
    property Text: String read FText write SetText;
  end;

  TPLCDataLayout = class(TObject)
  private
    FBits: Array of TPLCBit;
    FLength: Integer;
    procedure CleanUpBits;
    function GetBits(AIndex: Integer): TPLCBit;
    procedure SetLength(const Value: Integer);
  public
    constructor Create;
    destructor Destroy; override;
    property Bits[AIndex: Integer]: TPLCBit read GetBits;
    property Length: Integer read FLength write SetLength;
  end;

implementation

procedure TPLCBit.SetIsError(const Value: Boolean);
begin
  FIsError := Value;
end;

procedure TPLCBit.SetText(const Value: String);
begin
  FText := Value;
end;

constructor TPLCDataLayout.Create;
begin
  FLength := 0;
  System.SetLength(FBits, 0);

  inherited;
end;

destructor TPLCDataLayout.Destroy;
begin
  CleanUpBits;

  inherited;
end;

procedure TPLCDataLayout.CleanUpBits;
var
  i: Integer;
begin
  for i := 0 to System.Length(FBits) - 1 do
  begin
    FreeAndNil(FBits[i]);
  end;

  System.SetLength(FBits, 0);
end;

function TPLCDataLayout.GetBits(AIndex: Integer): TPLCBit;
begin
  result := FBits[AIndex];
end;

procedure TPLCDataLayout.SetLength(const Value: Integer);
begin
  FLength := Value;

  CleanUpBits;

  System.SetLength(FBits, FLength);
end;

end.
So. Wenn sich jetzt jemand fragt, warum ich dort drin immer explizit
Delphi-Quellcode:
System.SetLength(FBits, 0) // und
System.Length(FBits)
aufrufe, der stellt sich die gleiche Frage wie ich.

Ohne das explitzite vorgestellte System bekomme ich die Compilermeldung:
Zitat:

Zitat von Delphi Compiler
[Fehler] DataObjectsPLC.pas(91): Inkompatible Typen: 'Integer' und 'dynamic array'

Und wenn ich
Delphi-Quellcode:
uses
  // Delphi / VCL Units
  System, SysUtils;
verwende bekomme ich ein:
Zitat:

Zitat von Delphi Compiler
[Fehler] DataObjectsPLC.pas(7): Bezeichner redefiniert: 'System'

:gruebel: WAS zum Teufel hat sich hier eingeschlichen?

mirage228 15. Aug 2007 10:33

Re: Seltsame Includes?
 
HUST :mrgreen:

In einer deiner Klassen hast Du das ;)
Delphi-Quellcode:
procedure SetLength(const Value: Integer);
mfG
mirage228

Phoenix 15. Aug 2007 10:38

Re: Seltsame Includes?
 
:wall: Himmel.. blind oder blöd oder Beides. Danke!

Edit Nachtrag:
Total unbewusst. Das war vom Modelmaker automatisch generierter Property-Setter für das Property 'Length'.


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:33 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz