捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  粤ICP备10103342号-1 DELPHI盒子 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 盒子检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
 
广告
评论:预览式文件选择对话框示例
haiba 15332 2005/6/1 22:48:36
大家好:
  我是刚学Access数据库的,碰到一个问题想问一下,先谢了
有一个文本文件三列十几行数据格式(固定格式)如 2005  abcd  12345678要把它导入Access数据库当前窗口的子窗体内该如何编写?
jwbabc 13139 2005/3/11 18:14:06
其实这个问题早就在电脑报上发表过了!哈哈,一个道理
liumazi 12942 2005/2/28 23:40:34
对呀, 其实 TOpenPictureDialog 就是一个极好的例子; nihaoqiang兄, 很抱歉, 您的问题我不懂.
nihaoqiang 12823 2005/2/25 9:02:56
麻子兄,什么时候出任斑竹了?也不告诉小弟一声,小弟问你的问题看了吗?
http://bbs.2ccc.com/topic.asp?topicid=152630
oiwin 12719 2005/2/21 21:35:54
支持刘麻子
TO dinkysoft:继承TOpenDialog类加一点东西就可以封装成新的控件了(见下面).

unit OWOpenTxtDialog;

interface

uses
  Windows, Controls, Messages, ExtDlgs, SysUtils, Classes, Dialogs, StdCtrls, ExtCtrls;

type
  TOWOpenTxtDialog = class(TOpenDialog)
  private
    { Private declarations }
    FTxtPanel: TPanel;
    FTxtLabel: TLabel;
    FPaintPanel: TPanel;
    FTxtCtrl: TMemo;
    FSavedFilename: string;
    //function  IsFilterStored: Boolean;
  protected
    { Protected declarations }
    procedure DoClose; override;
    procedure DoSelectionChange; override;
    procedure DoShow; override;
    property ITxtCtrl: TMemo read FTxtCtrl;
    property TxtLabel: TLabel read FTxtLabel;

  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;

end.
progray 12708 2005/2/21 16:19:30
麻哥太酷了,真是盒子的荣幸!
tim001 12704 2005/2/21 14:35:38
麻哥又出新作!
dinkysoft 12697 2005/2/21 9:38:17
乖麻子,你把这个封装成类就好了。
dinkysoft 12696 2005/2/21 9:05:38
支持乖麻子
第一页 上一页 下一页 最后页 有 9 条纪录 共1页 1 - 9
 用户名:
 密 码:
自动登陆(30天有效)
 
  DELPHI盒子版权所有 技术支持:深圳市麟瑞科技有限公司 1999-2024 V4.01 粤ICP备10103342号-1 更新RSS列表