public { Public declarations } constructor Create(AOwner: TComponent); override; function Execute: Boolean; override; published { Published declarations } end;
procedure Register;
implementation
function TOWOpenTxtDialog.Execute; begin if NewStyleControls and not (ofOldStyleDialog in Options) then Template := 'DLGTEMPLATE' else Template := nil; Result := inherited Execute; //这地方有个小问题,运行正常,但返回值为FALSE,所以把返回值强制为TRUE Result := true; end;
constructor TOWOpenTxtDialog.Create(AOwner: TComponent); begin inherited Create(AOwner); Filter := '文本文件(*.txt)|*.txt|所有文件(*.*)|*.*'; FTxtPanel := TPanel.Create(Self); with FTxtPanel do begin Name := 'TxtPanel'; Caption := '; SetBounds(204, 5, 169, 200); BevelOuter := bvNone; BorderWidth := 6; TabOrder := 1; FTxtLabel := TLabel.Create(Self); with FTxtLabel do begin Name := 'TxtLabel'; Caption := '; SetBounds(6, 6, 157, 23); Align := alTop; AutoSize := False; Parent := FTxtPanel; end; FPaintPanel := TPanel.Create(Self); with FPaintPanel do begin Name := 'PaintPanel'; Caption := '; SetBounds(6, 29, 157, 145); Align := alClient; BevelInner := bvRaised; BevelOuter := bvLowered; TabOrder := 0; FTxtCtrl := TMemo.Create(Self); Parent := FTxtPanel; with FTxtCtrl do begin Name := 'PaintBox'; Align := alClient; ScrollBars := ssBoth; ReadOnly:=True; Parent := FPaintPanel; end; end; end; end;
procedure TOWOpenTxtDialog.DoClose; begin inherited DoClose; // end;
procedure TOWOpenTxtDialog.DoSelectionChange; var FullName: string; ValidPicture: Boolean; function ValidFile(const FileName: string): Boolean; begin Result := GetFileAttributes(PChar(FileName)) <> $FFFFFFFF; end; begin FullName := FileName; if FullName <> FSavedFilename then begin FSavedFilename := FullName; ValidPicture := FileExists(FullName) and ValidFile(FullName); if ValidPicture then try FtxtCtrl.Lines.LoadFromFile(FullName); FTxtlabel.Caption := ExtractFileName(FullName); // FPaintPanel.Caption := '; except ValidPicture := False; end; if not ValidPicture then begin FtxtLabel.Caption := '无内容'; FtxtCtrl.Text := '; end; end; inherited DoSelectionChange; end;
procedure TOWOpenTxtDialog.DoShow; var PreviewRect, StaticRect: TRect; begin { Set preview area to entire dialog } GetClientRect(Handle, PreviewRect); StaticRect := GetStaticRect; { Move preview area to right of static area } PreviewRect.Left := StaticRect.Left + (StaticRect.Right - StaticRect.Left); Inc(PreviewRect.Top, 4); FTxtPanel.BoundsRect := PreviewRect; FTxtCtrl.Text := '; FSavedFilename := '; FPaintPanel.Caption := '; FtxtPanel.ParentWindow := Handle; inherited DoShow; end;
procedure Register; begin RegisterComponents('oiwin', [TOWOpenTxtDialog]); end;