Thema: Delphi Proxies.dcu-Problem

Einzelnen Beitrag anzeigen

Benutzerbild von APP
APP

Registriert seit: 24. Feb 2003
Ort: Graz (A)
705 Beiträge
 
Delphi 7 Enterprise
 
#7
  Alt 28. Feb 2003, 06:21
Hallo,
ich kann Dir nur posten, was ich durch meine 1. Komponente gelernt habe:

Seit Delphi 6 müssen Komponenten in ein Design- und Runtime-Package aufgeteilt werden,wenn sie Property-Editoren enthalten (aus lizenzrechtlichen Gründen, wegen der Designtime Editoren).

Ich verwende einen FileOpenDialog für ein Logfile.

Frei nach Jeff Overcash (TeamB):
http://community.borland.com/article...,27717,00.html [20.02.2003]

Das Designtime-Package (also FlappErrorReg) sollte folgendes Beinhalten:
1. Die Registrier-Anweisungen
2. alle Property Editioren
3. alle Komponenten Editoren
4. DesignIDE und alle RuntimePackages die die Komponente selbst benötigt

Das Runtime-Package (FlappError) sollte folgendes Beinhalten:
1. die Komponente selbst
2. Optional, alle Forms die die Editoren benützen können WENN die Komponente diese zur Laufzeit SELBST aufrufen kann.

Delphi-Quellcode:
package flappErr;

{$R *.res}
{$R 'FlappError.dcr'}
{$ALIGN 8}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO ON}
{$SAFEDIVIDE OFF}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST OFF}
{$MINENUMSIZE 1}
{$IMAGEBASE $400000}
{$DESCRIPTION 'Armin''s FlappException Component (c) Armin P'}
{$DESIGNONLY}
{$IMPLICITBUILD OFF}

REQUIRES
  rtl,
  designide,
  vcl,
  vclactnband,
  vclx,
  DJCL70,
  SMCmpntD7,
  indy;

CONTAINS
  FlappError IN 'FlappError.pas', // Die Komponente
  FlappErrorReg IN 'FlappErrorReg.pas', // Designtime Package
  FlappErrorDlg IN 'FlappErrorDlg.pas{fFlappErrorDlg}, // graphischer Teil der Kompo
  Flapp_Utils IN 'Flapp_Utils.pas';
END.
Delphi-Quellcode:
UNIT FlappErrorReg;

{$include Compilers.inc}

INTERFACE

USES
{$IFDEF DELPHI_6_UP}
  DesignIntf,
  DesignEditors,
{$ELSE}
  dsgnintf,
{$ENDIF}
  FlappError;

  TYPE
  TLogFileNameProperty = CLASS(TPropertyEditor)
    FUNCTION AllEqual: boolean; OVERRIDE;
    PROCEDURE Edit; OVERRIDE;
    FUNCTION GetAttributes: TPropertyAttributes; OVERRIDE;
    FUNCTION GetValue: STRING; OVERRIDE;
    PROCEDURE SetValue(CONST Value: STRING); OVERRIDE;
  END;
PROCEDURE Register;

IMPLEMENTATION

USES SysUtils,
  Forms,
  Dialogs,
  Classes;

PROCEDURE Register;
BEGIN
  RegisterPropertyEditor(TypeInfo(STRING), TFlappError, 'LogFileName',
    TLogFileNameProperty);
  RegisterComponents('APP', [TFlappError]);
END;

FUNCTION TLogFileNameProperty.AllEqual: boolean;
VAR
  FirstVal : STRING;
  i : Integer;
BEGIN
  FirstVal := GetStrValue;
  Result := True;
  i := 1;
  WHILE Result AND (i < PropCount) DO
    BEGIN
      Result := Result AND (GetStrValueAt(i) = FirstVal);
      Inc(i);
    END;
END;

PROCEDURE TLogFileNameProperty.Edit;
VAR
  Dlg : TOpenDialog;
BEGIN
  Dlg := TOpenDialog.Create(Application);
  TRY
    WITH Dlg DO
      BEGIN
        Dlg.Filter := 'Logfile (*.log)|*.log|Textfile (*.txt)|*.txt|all Files|*.*';
        Dlg.DefaultExt := '*.log';
        Title := 'File for ' + TComponent(GetComponent(0)).Name;
        FileName := Value;
        IF Execute THEN Value := FileName;
      END;
  FINALLY
    FreeAndNil(Dlg);
  END
END;

FUNCTION TLogFileNameProperty.GetAttributes: TPropertyAttributes;
BEGIN
  Result := [paDialog]
END;

FUNCTION TLogFileNameProperty.GetValue: STRING;
BEGIN
  Result := GetStrValue;
END;

PROCEDURE TLogFileNameProperty.SetValue(CONST Value: STRING);
BEGIN
  SetStrValue(Value);
END;

END.
Delphi-Quellcode:
UNIT FlappError;

{$INCLUDE Compilers.inc}

INTERFACE

USES
...
...
  TFlappError = CLASS(TComponent) // Hauptklasse FlappError
  PUBLIC
    FOptions: TOptions;
    CONSTRUCTOR Create(Owner: TComponent); OVERRIDE;
    DESTRUCTOR Destroy; OVERRIDE;
  PRIVATE
    FActive: Boolean;
    FEmailOptions: TEmailOptions;
    FLogFileOptions: TLogFileOptions;
    FFileName: STRING;
...
    PROPERTY LogFileName: STRING READ FFileName WRITE FFileName; // Hier ist der Property-Editor aktiv
...
...
END.
Falls Dir das obige zu konfus erscheint, kann ich folgende Links empfehlen (dort gibt es auch Beispiele zum saugen):


Creating Custom Delphi Components, Part I


Creating Custom Delphi Components, Part II


Creating Custom Delphi Components, Part III


lG Armin
Armin P. Pressler
  Mit Zitat antworten Zitat