掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
ドラッグ&ドロップでファイル名とフルパスを取得してデータベースに格納するには? (ID:21512)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
上のTest部分のソースに間違ったものを送ってしまいました(汗 本物はこっちです… //////////////////////////////////////////////////////////// unit Test; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShellAPI, UnitDB; type TForm_Test = class(TForm) ListBox_FileName: TListBox; procedure FormCreate(Sender: TObject); private procedure WMDropFiles(var msg: TWMDropFiles); message WM_DROPFILES; public end; var Form_Test: TForm_Test; implementation {$R *.dfm} procedure TForm_Test.FormCreate(Sender: TObject); begin // ドラッグ&ドロップを受け付ける DragAcceptFiles(Handle, True); end; // フォームへドラッグ&ドロップされた場合 procedure TForm_Test.WMDropFiles(var msg: TWMDropFiles); var Path: array [0..255] of Char; total, i: Integer; DB : TUnitDB; begin // いくつのファイルがドロップされたかを得る total := DragQueryFile(Msg.Drop, $FFFFFFFF, Path, SizeOf(Path)); // ファイル名を1つずつ得る for i := 0 to total - 1 do begin DragQueryFile(msg.Drop, i, Path, SizeOf(Path)); // ListBox_FileName.Items.Add(Path); // これはOK // ListBox_FileName.Items.AddObject(Path, TObject(String(Path))); // これはNG // DB.Add(Path); // これもNG end; // ハンドルを解放 DragFinish(msg.Drop); end; end. ////////////////////////////////////////////////////// unit UnitDB; interface uses Classes, Dialogs, SysUtils; type TUnitDB = class public FFileName: TStrings; FFilePath: TStrings; procedure Add(const S: String); end; implementation procedure TUnitDB.Add(const S: String); begin FFileName.Add(S); FFilePath.Add(S); end; end. ////////////////////////////////////////////////////////
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.