Lazarus Indy Smtp 日本語対応 IdMessage1InitializeISO

Lazarus Lazarus Indy Smtp
にて、メール送信時の、Subject(題名)日本語対応

環境
Ubuntu 16
Lazarus 20.0.10

現象
メイル本文、送信者などの日本語対応ができたが
題名(Subject)が日本語にならない
IdMessage1のイベントで(IdMessage1InitializeISO)での
対応を行おうとIdMessage1InitializeISOを作成しようとするとにエラーとなり、作成できなかった

その他の対策(うまく行かなかった)
IdMessage(Indy)以外として
lNet,Synapse,jConvertなど行ったがうまくいかなかった(解決法があるかもしれないが。。。)

参考ページ
//https://wiki.freepascal.org/Networking_libraries
//https://www.migaro.co.jp/contents/support/technical_seminar_search/07th/Session3.pdf

対策
これでいいかわからないが、IdMessage1InitializeISO作成時のエラーをコメントアウトした

修正前(IdGlobal)

  GOffsetFromUTC: TDateTime = 0{$IFDEF HAS_DEPRECATED}{$IFDEF USE_SEMICOLON_BEFORE_DEPRECATED};{$ENDIF} deprecated{$ENDIF};
    {$IFDEF OSX}
  GMachTimeBaseInfo: TTimebaseInfoData;
    {$ENDIF}

修正後

  GOffsetFromUTC: TDateTime = 0
//    {$IFDEF HAS_DEPRECATED}{$IFDEF USE_SEMICOLON_BEFORE_DEPRECATED};{$ENDIF} deprecated{$ENDIF};
  GMachTimeBaseInfo: TTimebaseInfoData;
    {$IFDEF OSX}
  GMachTimeBaseInfo: TTimebaseInfoData;
    {$ENDIF}

修正前(TIdMessage)

IdCharSets,IdGlobalProtocols, IdMessageCoder, IdResourceStringsProtocols,

修正後

//IdCharSets,
IdGlobalProtocols, IdMessageCoder, IdResourceStringsProtocols,

本体
インスタンスはcreateせずに、設置したものを使用した

procedure TForm1.IdMessage1InitializeISO(var VHeaderEncoding: Char;
  var VCharSet: string);
begin
  VHeaderEncoding := 'B';
  VCharSet := 'UTF-8';
end; 
procedure TForm1.Button1Click(Sender: TObject);
begin
  try
  try
    IdSMTP1.HOST:='xxx.com';
    IdSMTP1.PORT:=587;
    IdSMTP1.Username:='xxx@xxx.com';
    IdSMTP1.Password:='xxxxxx';

    IdSMTP1.Connect;

    IdMessage1.ContentType := 'text/plain'; // コンテンツタイプ
    IdMessage1.CharSet := 'UTF-8'; // 文字セット
    IdMessage1.ContentTransferEncoding := 'BASE64';
    IdMessage1.From.Address := 'info@atiinelab.com';
    IdMessage1.Recipients.EMailAddresses := 'xxxxx@xxxx.com';
    IdMessage1.ReplyTo.EMailAddresses:='xxx@xxx.com';
    IdMessage1.Body.Text :='メール本文';
//    IdMessage1.Subject := EncodeHeader(UTF8Encode('アカウントを送付します'), '', 'B', 'UTF-8');
    IdMessage1.Subject                   := '日本語の題名';
    IdMessage1.From.Name := EncodeHeader('送信者名', '', 'B', 'UTF-8');

    //*=== メール送信 ===*/
    IdSMTP1.Send(IdMessage1);
  except
  end;
  finally
    //*=== SMTPサーバの切断 ===*/
    if IdSMTP1 <> nil then
    begin
      IdSMTP1.Disconnect;
    end;
  end;
end;    

can not load default Mysql library(“libmysqlclient.so18” or “libmysqlclient.so”).check your installation

Ubuntu16 にて、Mysqlに接続しようとしたら
can not load default Mysql library(“libmysqlclient.so18” or “libmysqlclient.so”).check your installation
なるエラーがでた

環境
Ubuntu16
Lazarus 2,0,10
他の環境では動いているのに

クライアントソフトをインストール

sudo apt install mysql-client

だめなので、一応サーバを入れてみる

sudo apt install mysql-server

やはりだめ
指摘されている内容を入れてみる

sudo apt-get install libmysqlclient-dev

エラーメッセージが変わった

TMySQL55Connection can not work with the installed MySQL client version:Expected(5.5),got(5.7.31)

Lazarusのコンポーネントを
TMySQL55Connection
から
TMySQL57Connection
へ変更してみた。

無事接続できた。

追記

別の環境で、発生した時

sudo apt-get install libmysqlclient-dev

だけで、対策ができた。

Ubuntu 16.04 ftpクライアントツールをインストール

Ubuntu 16.04 ftpクライアントツールをインストール

filezillaをインストールしてみた

google filezilla ubuntu install

参考

Ubuntu 18.04 に最新版のFileZillaをインストールし設定するまでの手順

最新版のリポジトリを追加

sudo add-apt-repository ppa:sicklylife/filezilla

インストール

sudo apt update
sudo apt install filezilla

実行

filezilla

無事、インストールができました。

Ubuntu 16.04 Mysqlクライアントツールを使う

Ubuntu 16.04
で、Mysqlクライアントソフトとして

Windows版の
HeidisqlをWineにてインストールしてみた。

Ubuntu 14.04
の場合と同じように使うことができた。

Ubuntu 14.04 Wine Heidisqlを使う


と同じ内容であるが、手順は以下となります。

Wineのインストール

https://symfoware.blog.fc2.com/blog-entry-1400.html
を、参考にする

sudo apt-get install wine

インストール中に
ttf-mscorefonts-installerの設定

が表示された時には
タブキーにて「了解」を選択しエンターキーを入力。

インストールが完了したら

winecfg
で、インストールされたWineのバージンを確認

「Wineについて」のタブを開く
1.6.2

HeidiSQL
をダウンロード
10.xx.xx
だと、起動しなかったので、

9.3.0.4984

https://heidisql.jp.uptodown.com/windows/download/429381
を、ダウンロード

ダウンロードしたものを、右クリックでWine Windows プログラムローダで開く

一度、インストールして、競合し、不具合になる時は
フォルダーを削除

sudo find ./ -name “Heidi*”
./.wine/drive_c/users/Public/Start Menu/Programs/HeidiSQL
あたり。

Lazarus 時刻を設定し時刻になったらイベントを発生する

予約設定時間になった時に処理をする仕組みを作ってみる

環境
Ubuntu16
Lazarus 2.0.10

参考ページ
https://www.ipentec.com/document/delphi-get-now-datetime
https://www.ipentec.com/document/delphi-datetime-to-string
http://mrxray.on.coocan.jp/Delphi/plSamples/004_TimerTest.htm

ポイント
・現時刻を書式設定で文字列に変換
・タイマーで、毎回(2秒毎に)チェックを行う
・状態変数を持ち、変化時のみにイベント処理をできるようにする

プログラム

private
    fltime:integer;
 
procedure TForm1.Button1Click(Sender: TObject);
//https://www.ipentec.com/document/delphi-get-now-datetime
//https://www.ipentec.com/document/delphi-datetime-to-string
//http://mrxray.on.coocan.jp/Delphi/plSamples/004_TimerTest.htm

var
  dt:TDateTime;
  str:string;
begin
  dt:=Now;
  DateTimeToString(str, 'HH:mm',dt);
  Edit2.Text:=str;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  edit3.Text:=Combobox1.Text+':'+Combobox2.Text;
end;

procedure TForm1.ComboBox2Change(Sender: TObject);
begin
  ComboBox1Change(Sender);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  fltime:=0;
  combobox1.ItemIndex:=0;
  combobox2.ItemIndex:=0;
  ComboBox1Change(Sender);
  timer1.Enabled:=True;
  timer1.Interval:=2000; //2000ミリ秒(2秒)ごとに処理を行う
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Button1Click(Sender);
  if edit3.Text=edit2.Text then
   begin
   if fltime=0 then
    begin
    MessageDlg('メッセージ', mtInformation, [mbYes], 0);
    fltime:=1;
    end;
   end
  else
  fltime:=0;
end;  

設定(初期設定)
Combobox1
00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23
Combobox2
00,05,10,15,20,25,30,35,40,45,50,55
を、
オブジェクトインスペクタ
プロパティ
Items
Stringエディタから
初期値を設定

Lazarusコンボボックスの初期値設定

Lazarusコンボボックスの初期値設定

時間設定のコンボボックスを作成してみた
初期値として
時間(0から23)と分(0から55分で5分刻み)
をセットする

時間
00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23


00,05,10,15,20,25,30,35,40,45,50,55
とする。(文字列)

まず、2つのコンボボックスを作り

オブジェクトインスペクタ
プロパティ
Items
Stringエディタから
初期値を入れることができた

Lazarus で、リストデータの移動処理を行ってみた

Lazarus で、リストデータの移動処理を行ってみた

リストデータの受け渡しのための
データの移動追加の処理を行ってみた

環境
Ubuntu16
Lazarus 2.0.10

参考ページ
https://www.migaro.co.jp/contents/products/delphi400/tips/introduction/4_20/02/01.html
http://delfusa.main.jp/delfusafloor/archive/www.nifty.ne.jp_forum_fdelphi/faq/00055.htm
https://www.migaro.co.jp/contents/products/delphi400/tips/introduction/4_20/02/01.html
http://dp25299446.lolipop.jp/delphi_tips/tips0045.html

ポイント
リストにはListBoxを使う
・項目追加
 ListBox.Items.Add(文字列)
・項目削除
ListBox.Items.Delete(番号);
 選択している行の場合
ListBox.Items.Delete(ListBox.ItemIndex);
・選択しているデータ
 ListBox1.Items[ListBox.ItemIndex]
・選択しているかの判断
 if (ListBox.ItemIndex > -1) Then 選択されている else 選択されていない
・データの永続的処理(ロード、セーブ)
ListBox.Items.LoadFromFile(ファイル名);
ListBox.Items.SaveToFile(ファイル名);
・その他論理演算
 等しい時 =
 等くない時 <>
 論理and and

プログラム

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Caption:='>';
  Button2.Caption:='<';
  Button4.Caption:='adddata';
  Button5.Caption:='delete';
  Button6.Caption:='save';
  Button3.Visible:=False;

  ListBox1.Items.Add('abc-1');
  ListBox1.Items.Add('abc-2');
  ListBox1.Items.Add('abc-3');
  Button3Click(Sender);
  if FileExists('listdata.txt') then
   ListBox2.Items.LoadFromFile('listdata.txt');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox2.Items.Add(ListBox1.Items[ListBox1.ItemIndex]);
  ListBox1.Items.Delete(ListBox1.ItemIndex);
  Button3Click(Sender);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ListBox1.Items.Add(ListBox2.Items[ListBox2.ItemIndex]);
  ListBox2.Items.Delete(ListBox2.ItemIndex);
  Button3Click(Sender);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
   if  (ListBox1.ItemIndex > -1) and (ListBox1.Items.Count <> 0)  then
    button1.Enabled := True
   else
    button1.Enabled := False;
   if  (ListBox2.ItemIndex > -1) and (ListBox2.Items.Count <> 0)  then
    begin
      button2.Enabled := True;
      button5.Enabled := True;
    end
   else
    begin
      button2.Enabled := False;
      button5.Enabled := False;
    end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
 ListBox2.Items.Add(edit2.Text);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
 ListBox2.Items.Delete(ListBox2.ItemIndex);
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  ListBox2.Items.SaveToFile('listdata.txt');
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
  if  edit2.text <> '' then
    button4.Enabled := True
   else
    button4.Enabled := False;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  edit1.Text:=ListBox1.Items[ListBox1.ItemIndex];
  Button3Click(Sender);
end;

procedure TForm1.ListBox2Click(Sender: TObject);
begin
  Button3Click(Sender);
end;
            

Lazarusを日本語化に

Ubuntu16Desktopの英語環境でセットアップした所
Lazarusが英語環境となっていた

Ubuntu16Desktopの環境を
日本語環境に切り替えてた所

Lazarusも日本語環境になった

メニューなどが、日本語となっている

プログラムへの日本語入力はできないので
メモなどで日本語を打ち
コピペする必要がある

Conoha Ubuntu16Desktop日本語化

Conoha Ubuntu16Desktop日本語化にしてみました

参考
https://www.server-world.info/query?os=Ubuntu_20.04&p=japanese
https://qiita.com/myalpine/items/fb45b222924b2e61ea9f

右上の歯車の
System Settings..

から
LanguageSupport

「install/Remove Language..」
を選択
Japanes
を選択し
「Apply」

再起動をして有効にする

再起動は

ttps://eng-entrance.com/linux-ubuntu-reboot

を、参考に

右上のShutdownを選択した後に
Rebootを選択する

LazarusからShellを起動

LazarusからShellを起動してみました

環境
Ubuntu16
Lazarus 2.0.10

ポイント
TProcessからShellを起動
Shellの完了待ちとする方法と、完了待ちしない方法を選択できます

参考ページ
https://wiki.freepascal.org/Executing_External_Programs
https://stackoverflow.com/questions/26977422/execute-commands-in-the-linux-commandline-lazarus-free-pascal

設定
uses
,Process; //追加

プログラム

procedure TForm1.Button1Click(Sender: TObject);
var
  AProcess: TProcess;
begin
  AProcess := TProcess.Create(nil);
  AProcess.CommandLine:='/bin/bash /home/user/xxx/test02.sh';
  AProcess.Options := AProcess.Options + [poWaitOnExit];
  AProcess.Execute;

  AProcess.Free;
  button1.Caption:='ok';
end;  

以下をなくすと、完了を待たずに次のステップに進みます。

  AProcess.Options := AProcess.Options + [poWaitOnExit];

test02.shの例
動作確認用

#!/bin/bash

cd /home/user/xxx/
ls >> /home/user/xxx/log01.txt

Python起動例

#!/bin/bash

source /home/user/env/bin/activate
cd /home/user/xxx/
python test.py
deactivate