Thema: Delphi Pointer - Wie verwenden?

Einzelnen Beitrag anzeigen

Andreas L.
(Gast)

n/a Beiträge
 
#8

Re: Pointer - Wie verwenden?

  Alt 2. Mär 2009, 22:17
Zitat von mkinzler:
Was macht/soll den SaveValues den (machen)?
In FileList eintragen, welche Dateien aktiviert (checked) sind.

TFiles sieht so aus:

Delphi-Quellcode:
  TFiles = class(TObjectList)
  protected
    procedure SetItem(Index: Integer; Value: TFile);
    function GetItem(Index: Integer):TFile;
  public
    function Add:Integer;
    function GetFileByFileName(FileName: String):TFile;
    function CheckedCount:Integer;
    function GetCheckBoxStyle:TCheckBoxState;
    property Items[Index: Integer]:TFile read GetItem write SetItem; default;
  end;

  TFile = class(TPersistent)
  private
    FFileName: String;
    FBrowser: String;
    FProfile: String;
    FFormat: TCookieFormat;
    FTitle: String;
    FSize: Int64;
    FChecked: Boolean;
  protected
    procedure Assign(Source: TFile);
  published
    property FileName: String read FFileName write FFileName;
    property Browser: String read FBrowser write FBrowser;
    property Profile: String read FProfile write FProfile;
    property Format: TCookieFormat read FFormat write FFormat;
    property Title: String read FTitle write FTitle;
    property Size: Int64 read FSize write FSize;
    property Checked: Boolean read FChecked write FChecked;
  end;

...

{ TFile }
procedure TFile.Assign(Source: TFile);
begin
  FFileName := Source.FileName;
  FBrowser := Source.Browser;
  FProfile := Source.Profile;
  FFormat := Source.Format;
  FTitle := Source.Title;
  FSize := Source.Size;
  FChecked := Source.Checked;
end;

{ TFiles }
procedure TFiles.SetItem(Index: Integer; Value: TFile);
begin
  inherited Items[Index] := Value;
end;

function TFiles.GetItem(Index: Integer):TFile;
begin
  Result := inherited Items[Index] as TFile;
end;

function TFiles.Add:Integer;
var
  NewFile: TFile;
begin
  NewFile := TFile.Create;
  Result := inherited Add(NewFile);
end;

function TFiles.GetFileByFileName(FileName: string):TFile;
var
  iFile: Integer;
begin
  Result := TFile.Create;
  Result.Checked := False;
  for iFile := 0 to Count -1 do
  begin
    if LowerCase(Items[iFile].FileName) = LowerCase(FileName) then
    begin
      Result.Assign(Items[iFile]);
      Break;
    end;
  end;
end;

function TFiles.CheckedCount:Integer;
var
  iFile: Integer;
begin
  Result := 0;
  for iFile := 0 to Count -1 do
    if Items[iFile].Checked then
      Inc(Result);
end;

function TFiles.GetCheckBoxStyle:TCheckBoxState;
begin
  Result := cbUnchecked;
  if CheckedCount = Count then
    Result := cbChecked
  else if CheckedCount > 0 then
    Result := cbGrayed;
end;
  Mit Zitat antworten Zitat