From c94821adb611a045bf74b657228098cc04115895 Mon Sep 17 00:00:00 2001 From: Nick's Hardware Youtube Channel <56885781+nickshardware@users.noreply.github.com> Date: Mon, 22 May 2023 19:12:39 -0400 Subject: [PATCH] drag and drop support --- rtbinsrcfm.lfm | 6 ++++-- rtbinsrcfm.pas | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/rtbinsrcfm.lfm b/rtbinsrcfm.lfm index 7bd7890..6e33c1c 100644 --- a/rtbinsrcfm.lfm +++ b/rtbinsrcfm.lfm @@ -1,14 +1,16 @@ object Form1: TForm1 - Left = 502 + Left = 467 Height = 560 - Top = 400 + Top = 370 Width = 858 + AllowDropFiles = True BorderIcons = [biSystemMenu, biMinimize] BorderStyle = bsDialog Caption = 'Form1' ClientHeight = 560 ClientWidth = 858 OnCreate = FormCreate + OnDropFiles = FormDropFiles LCLVersion = '2.0.10.0' object InFile: TButton Left = 16 diff --git a/rtbinsrcfm.pas b/rtbinsrcfm.pas index 903f1b2..fe9ba53 100644 --- a/rtbinsrcfm.pas +++ b/rtbinsrcfm.pas @@ -6,10 +6,10 @@ interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, - LazFileUtils, SpinEx,rtcodegen; + LazFileUtils, Types, SpinEx,rtcodegen; Const - ProgramName = 'RtBinSrc v1.2 By RetroNick - Released May 19 - 2023'; + ProgramName = 'RtBinSrc v1.3 By RetroNick - Released May 22 - 2023'; type @@ -42,8 +42,10 @@ TForm1 = class(TForm) procedure CopyToClipboardClick(Sender: TObject); procedure FormatRadioGroupClick(Sender: TObject); procedure FormCreate(Sender: TObject); + procedure FormDropFiles(Sender: TObject; const FileNames: array of String); procedure ImportClick(Sender: TObject); procedure InFileClick(Sender: TObject); + procedure InFileDragDrop(Sender, Source: TObject; X, Y: Integer); procedure LanRadioGroupClick(Sender: TObject); procedure NumTypeRadioGroupClick(Sender: TObject); procedure SaveAsClick(Sender: TObject); @@ -140,6 +142,34 @@ procedure TForm1.FormCreate(Sender: TObject); CGSetMemoProc(@FMemoAppend); end; +procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String + ); +var + MousePoint: TPoint; +begin + if High(Filenames) > 0 then + begin + ShowMessage('Drag only one file!'); + exit; + end; + + if FileExists(FileNames[0]) then + begin + OpenDialog.FileName:=FileNames[0]; + EditFileName.Caption:=FileNames[0]; + EditArrayName.Text:=LowerCase(ExtractFileName(ExtractFileNameWithoutExt(FileNames[0]))); + Import.Enabled:=True; + end + else + begin + ShowMessage('Invalid File/Directory!'); + exit; + end; + + MousePoint := ScreenToClient(Mouse.CursorPos); + if NOT (PtInRect(InFile.BoundsRect, MousePoint) or PtInRect(EditFilename.BoundsRect, MousePoint)) then ImportClick(Self); +end; + procedure TForm1.ImportClick(Sender: TObject); var error : word; @@ -200,6 +230,13 @@ procedure TForm1.InFileClick(Sender: TObject); end; end; +procedure TForm1.InFileDragDrop(Sender, Source: TObject; X, Y: Integer); +begin + +end; + + + procedure TForm1.LanRadioGroupClick(Sender: TObject); begin if Processing then exit;