if Ord(Key)=VK_RIGHT then
begin
if ActiveControl is TStringGrid then
begin
if TStringGrid(ActiveControl).EditorMode then
begin
Key:=#0;
//Exit;
end;
end;
end;
if Ord(Key)=VK_RIGHT then
begin
if ActiveControl is TStringGrid then
begin
if TStringGrid(ActiveControl).EditorMode then
begin
ShowMessage('VK_RIGHT');
Key:=#0;
//Exit;
end;
end;
end;
type
・・・
//Col毎のIMEの制御
type
_TGrid = class(TCustomGrid);
private
{ Private 宣言 }
・・・
procedure TFormCollaboration.StringGrid1GetEditText(Sender: TObject; ACol,
ARow: Integer; var Value: string);
begin
//IMEの制御
with TEdit(_TGrid(Sender).InplaceEditor) do
begin
ImeMode := imDisable; //日本語入力OFFは imDisable
end;
end;
【Enterキーでカーソルは下のセルへ移動】
procedure TFormCollaboration.FormKeyPress(Sender: TObject; var Key: Char);
begin
//[Enter]キーでコントロールを移動
//StringGridは編集可能にFormCreateで設定しておく
//->忘れるとセルの移動にEnter×2回必要!
//この方法を使う時はKeyPreview:=True;をFormCreateで指定。
if Ord(Key)=VK_RETURN then
begin
if ActiveControl is TStringGrid then
begin
if TStringGrid(ActiveControl).EditorMode then
begin
//VK_TABではカーソルがレコードの項目を右へ移動。
//ActiveControl.Perform(WM_KEYDOWN,VK_TAB,0);
//VK_DOWNにすると同じ項目の次のレコードへ移動。
ActiveControl.Perform(WM_KEYDOWN,VK_DOWN,0);
Key:=#0;
end;
end else begin
SelectNext(ActiveControl,True,True);
Key:=#0;
end;
end;
end;
【列の非表示】※StringGridの初期化時と採点欄の切り替え時の両方に設定
//列幅の自動調整(やるなら列の非表示設定の前に実行)
for iCOL := 0 to StringGrid1.ColCount-1 do
begin
MaxColWidth := 0;
for iROW := 0 to StringGrid1.RowCount-1 do
begin
TmpColWidth := Canvas.TextWidth(StringGrid1.Cells[iCOL,iROW])+10;
if MaxColWidth < TmpColWidth then
begin
MaxColWidth := TmpColWidth;
end;
end;
StringGrid1.ColWidths[iCOL] := MaxColWidth;
end;
//必要な列のみ表示
for i := 1 to StringGrid1.ColCount-1 do
begin
if i<>StrToInt(ComboBox1.Text) then
begin
StringGrid1.ColWidths[i]:=-StringGrid1.GridLineWidth;
//StringGrid1.ColWidths[i]:=-1;
end else begin
StringGrid1.ColWidths[i]:=45;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;
procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.message = WM_KEYDOWN then begin
end;
end;
procedure TFormCollaboration.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
//StringGrid上で押された右矢印キーを無効化する
if Msg.message = WM_KEYDOWN then
begin
if ActiveControl is TStringGrid then
begin
if TStringGrid(ActiveControl).EditorMode then
begin
if Msg.wParam = VK_RIGHT then
begin
ShowMessage('捕まえた!');
Key:=#0;
end;
end;
end;
end;
end;
うわーん。Keyが「未定義の識別子」エラーに!!! よく見たら・・・
procedure TFormCollaboration.AppMessage(var Msg: TMsg; var Handled: Boolean);
procedure TFormCollaboration.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
//StringGrid上で押された右矢印キーを無効化する
if Msg.message = WM_KEYDOWN then
begin
if ActiveControl is TStringGrid then
begin
if TStringGrid(ActiveControl).EditorMode then
begin
if Msg.wParam=VK_RIGHT then
begin
//単に0を代入してwParamを書き換え
Msg.wParam := 0;
end;
end;
end;
end;
左矢印キーの押し下げにも、忘れずに対応☆
//StringGrid上で押された左矢印キーを無効化する
if Msg.message = WM_KEYDOWN then
begin
if ActiveControl is TStringGrid then
begin
if TStringGrid(ActiveControl).EditorMode then
begin
if Msg.wParam=VK_LEFT then
begin
//単に0を代入してwParamを書き換え
Msg.wParam := 0;
end;
end;
end;
end;
end;
翌日、左右の制御を合体させた方がイイと気づき、上の2つを合体させて・・・
procedure TFormCollaboration.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
//StringGrid上で押された左右の矢印キーを無効化する
if Msg.message = WM_KEYDOWN then
begin
if ActiveControl is TStringGrid then
begin
if TStringGrid(ActiveControl).EditorMode then
begin
if Msg.wParam=VK_RIGHT then
begin
//単に0を代入してwParamを書き換え
Msg.wParam:=0;
end;
if Msg.wParam=VK_LEFT then
begin
//単に0を代入してwParamを書き換え
Msg.wParam:=0;
end;
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
//Python39-32へのPath
AppDataDir:string;
begin
・・・
if DirectoryExists(AppDataDir) then
begin
//フォルダが存在したときの処理(コメント化)
//MessageDlg('Embeddable Pythonが利用可能です。',
// mtInformation, [mbOk] , 0);
PythonEngine1.AutoLoad:=True;
GitHubのPython4Delphiのダウンロードページには「The project is licensed under the MIT License.」とある。これは「改変・再配布・商用利用・有料販売すべてが自由かつ無料」であること、及び使用するにあたっての必須条件はPython4Delphiの「著作権を表示すること」と「MITライセンスの全文」or 「 MITライセンス全文へのLink」をソフトウェアに記載する、もしくは、別ファイルとして同梱しなさい・・・ということを意味する。
procedure TForm1.CMShowingChanged(var Msg: TMessage);
begin
inherited; {通常の CMShowingChagenedをまず実行}
if Visible then
begin
Update; {完全に描画}
//Formの表示終了時に以下を実行
Panel1.Height:=intPH;
intPH:=Panel1.Height;
intFH:=Form1.Height;
end;
end;
Formが生成される際に、Panel1とFormの高さをプログラムから指示して決定。
procedure TForm1.FormCreate(Sender: TObject);
begin
//Panel1とFormの高さを記憶する変数を初期化
intPH:=200;
intFH:=480;
end;
Formの大きさの変更イベントに合わせて、Panel1の高さを計算して決定。
procedure TForm1.FormResize(Sender: TObject);
begin
//比率を維持してPanel1の高さを変更
Panel1.Height:=Trunc(Form1.Height * intPH/intFH);
end;
procedure TForm1.CMShowingChanged(var Msg: TMessage);
begin
inherited; {通常の CMShowingChagenedをまず実行}
if Visible then
begin
Update; {完全に描画}
//Formの表示終了時に以下を実行
Memo1.Width:=intMW;
intMW:=Memo1.Width;
intFW:=Form1.Width;
end;
end;
Formが生成される際に、MemoとFormの大きさをプログラムから指示して決定。
procedure TForm1.FormCreate(Sender: TObject);
begin
//MemoとFormの幅を記憶する変数を初期化
intMW:=480;
intFW:=640;
end;
Formの大きさの変更イベントに合わせて、Memoの幅を計算して決定。
procedure TForm1.FormResize(Sender: TObject);
begin
//比率を維持してMemoの幅を変更
Memo1.Width:=Trunc(Form1.Width*intMW/intFW);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
//PythonのScriptを入れる
strScrList:TStringList;
//Pythonから送られたデータを保存する
strAnsList:TStringList;
begin
end;
最初に、Memo1を初期化し、データの入れ物をそれぞれ準備する。
begin
//初期化
Memo1.Clear;
//Scriptを入れるStringList
strScrList:=TStringList.Create;
//結果を保存するStringList
strAnsList:=TStringList.Create;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
//PythonのScriptを入れる
strScrList:TStringList;
//Pythonから送られたデータを保存する
//strAnsList:TStringList; //コメント化してしまう
begin
GitHubのPython4Delphiのダウンロードページには「The project is licensed under the MIT License.」とある。これは「改変・再配布・商用利用・有料販売すべてが自由かつ無料」であること、及び使用するにあたっての必須条件はPython4Delphiの「著作権を表示すること」と「MITライセンスの全文」or 「 MITライセンス全文へのLink」をソフトウェアに記載する、もしくは、別ファイルとして同梱しなさい・・・ということを意味する。
「python -m pip list」で「python.exe: No module named pip」が返る場合は、 pythonNN._pthファイルの修正(# import siteの前にある記号#(ナンバー)とその後ろの半角スペースを削除して import site だけにするコメント化の解除手続き)が正しく行われていない可能性が高い。 また、複数のライブラリのインストールを行うと、 pythonNN._pthファイル が修正前の状態に戻されてしまうこともあるようだ。要確認。
4.Numpyのインストール
続いて「愛しのNumpy」をインストール。
>python -m pip install numpy と入力してEnter!
「生きていてよかった」と思える至福の一瞬がここに。
警告:Consider adding this directory to PATH (このディレクトリをPATHに追加することを検討してください) は、まったく気にしない。Numpyが入ればいいのだ。わはは*(^_^)*♪
5.OpenCVのインストール
さらに、視力0.01かつ老眼&緑内障の恐れありと診断(2万ン千円も払ったのにイタいことばかり言いやがって:チ○ショー!「我が愛と哀しみの人間ドック2021年の記録」より抜粋)された私の眼に代わるSecret Weapon、目にも止まらぬ 走召 高速!でマークシートを読んでくれる機械の眼という意味がほぼない長い前置きを乗り越え、今、怒涛のクライマックス。「OpenCV」ライブラリがいよいよ My PC へ!
FILES: Readme.txt This file. Python.txt Infos about Python, and further references. Changes.txt List of all changes since the first release. Tutorial.txt A simple tutorial to use the PythonEngine To do.txt A to do list. Deploying P4D.pdf Notes on the Deployment of your applications using Python for Delphi. C++ Builder Notes.txt Notes on using C++Builder with the Python for Delphi components. PythonAtom.hlp A help file explaining the use of TPythonAtom Demos A folder containing several demos of Python for Delphi. Components\Python.* The “Python for Delphi” packages. Components\Sources\Core The source folder of the core “Python for Delphi”. Lib Library of Python modules. PythonIDE A Python developpment environment written in Delphi. See PythonIDE\Readme.txt for the required components. Modules Contains the Delphi\Delphi.dpr project that creates the Modules\Delphi.pyd Python module that allows you to interact with Delphi VCL objects from Python.
INSTALLATION: install the Python for Windows distribution (http://www.python.org/).
1) Install the core components For recent versions of Delphi, install the “Python_d” package located in the Components folder and add the folder “…\Components\Sources\Core” to the library path.
For recent versions of Delphi, install the “PythonVCL_d” package located in the Components folder and add the folder “…\Components\Sources\Core” to the library path.
2) this is optional ・・・とあるので、オプションならやらなくてもいいか!ということで実行しない。
3) Build Modules\Delphi\Delphi.dpr (This is optional and unsupported)
Once the project is build you can either extend the Python path with ..\Modules or copy ..Modules\Delphi.pyd to C:\Python24\DLLs, to be able to import the Delphi module from Python.
Note that you can try this module by invoking the ..\Modules\TestApp.py script.
3) This is optional and unsupported ・・・とあり、オプションである上にサポートなしとあるので、これも実行しない。
GitHubのPython4Delphiのダウンロードページには「The project is licensed under the MIT License.」とある。これは「改変・再配布・商用利用・有料販売すべてが自由かつ無料」であること、及び使用するにあたっての必須条件はPython4Delphiの「著作権を表示すること」と「MITライセンスの全文」or 「 MITライセンス全文へのLink」をソフトウェアに記載する、もしくは、別ファイルとして同梱しなさい・・・ということを意味する。
RAD Studio 12.0(Delphi 12.0 Athens)のリリースに合わせ、Python4Delphi も更新されました。 RAD Studio 12.0(Delphi 12.0 Athens)へのインストールに対応した Python4Delphi (20231109版)のインストール記事は、以下のリンク先にあります。
RAD Studio 12.0(Delphi 12.0 Athens)に Python4Delphi をインストールされる場合は、こちらをご参照ください。
Use for Delphi Seattle (10.4) or later to install all packages in one step.
Clone or copy the Python4Delphi git repository to a folder of your choice. The setup.ini file assumes that the folder is called “P4D”. If you chose to name your folder differently then modify the “Folder” option in setup.ini.
Close all Delphi IDEs running.
Run MultiInstaller.exe
Select the packages you want and press Next
In the dialog box specify the parent folder of “P4D” (i.e. the folder containing the directory to which you have copied Python4Delphi) and the Delphi target version. Then press Next to install the components
GitHubのPython4Delphiのダウンロードページには「The project is licensed under the MIT License.」とある。これは「改変・再配布・商用利用・有料販売すべてが自由かつ無料」であること、及び使用するにあたっての必須条件はPython4Delphiの「著作権を表示すること」と「MITライセンスの全文」or 「 MITライセンス全文へのLink」をソフトウェアに記載する、もしくは、別ファイルとして同梱しなさい・・・ということを意味する。