Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#30

AW: Canvas: "erlaubt kein Zeichnen"

  Alt 9. Feb 2012, 23:02
Hier mal ein Auszug aus der mSuM.pas ... um die Krankheit zu zeigen
Delphi-Quellcode:
...
type Bildschirm = class (TObject)

  public
    constructor init;
    procedure loescheAlles;
    function breite:GanzeZahl;
    function hoehe:GanzeZahl;
    destructor gibFrei;

  protected { Protected,da diese Methode nur in dieser Unit verf¸gbar sein soll}
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
end;
...
implementation
...
var BFormular:tForm;
    derBildschirm:Bildschirm;
...
constructor Bildschirm.init;
begin
  MouseStat:=TMouseStat.Create;
  Application.Initialize;
  Application.CreateForm(tForm,BFormular);
  BFormular.Caption:=Version;
  BFormular.Top:=5;
  BFormular.Left:=5;
  BFormular.Height:=screen.height-74;
  BFormular.Width:=screen.width-20;
  BFormular.WindowState:=wsMaximized;
  BFormular.Align:=alClient;
  BFormular.Color:=weiss;
  BFormular.OnMouseDown:=MouseStat.MouseDown;
  BFormular.OnMouseMove:=MouseStat.MouseMove;
  BFormular.OnMouseUp:=MouseStat.MouseUp;
  BFormular.OnDblClick:=MouseStat.MouseDblClk;
  BFormular.OnKeyDown:=derTastaturpuffer.FormKeyDown;
  BFormular.OnKeyPress:=derTastaturpuffer.FormKeyPress;
  BFormular.OnCloseQuery:=derBildschirm.FormCloseQuery;
  BFormular.show;
  BFormular.repaint; {*}
  BFormular.update; {*}
  derBildschirm:=self;
end;
Spätestens jetzt sollte klar sein, warum man auf Formular nicht zugreifen kann
Im Netz habe ich aber etwas gefunden, wo jemand ganz schlau war und eine tolle Modifikation vorgenommen hat.
Delphi-Quellcode:
type Bildschirm = class (TObject)

  public
    Form:tForm;
    ...
end;

constructor Bildschirm.init;
begin
  ...
  Form:= BFormular;
// derBildschirm:=self;
end;
Wie man sieht, da war ein echter Experte am Werk
Mindestens so gut wie der Entwickler dieser Unit

Um hier an einen Canvas zu kommen hilft wohl nur screen.activeForm.Canvas , so wird auch in dieser Unit der Canvas ermittelt.
Delphi-Quellcode:
constructor Stift.init;
begin
  if screen.activeForm=nil then
  begin
    MessageDlg('Ein Stift wurde OHNE oder VOR dem Bildschirm initialisiert.',mtError,[mbOK],0);
    Halt;
  end;

  kenntCanvas:=screen.activeForm.Canvas;
  hatStift:=TPen.Create;
  hatPinsel:=TBrush.Create;
  zFarbe:=clBlack;
  ...
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat