月別アーカイブ: 2020年8月

Lazarus StringGrid重複するデータを削除

StringGridで、カラムの中で、重複する情報がある場合削除する処理を作ってみた

DBのSQL文のdistinct(重複レコードの削除)のような処理

処理は、まず指定カラムで、並び替えを行い
同じカラムの内容がつづいたものを、削除する処理とした

並び替えの処理は、Webにある既存の処理を使った

//http://delfusa.main.jp/delfusafloor/archive/www.nifty.ne.jp_forum_fdelphi/faq/00084.htm
ソート処理

Procedure GridSort(Grid : TStringGrid;SortCol : LongInt);
var
   St, St2 : TStringList;
   i : Integer;
begin
     St := TStringList.Create;
     ST.Assign(Grid.Cols[SortCol]);
     For i := 1 To Grid.FixedRows Do
        St.Delete(0);
     For i := Grid.FixedRows To Grid.RowCount - 1 Do
     Begin
                                            St2 := TStringList.Create;
       St2.Assign(Grid.Rows[i]);
       St.Objects[i - Grid.FixedRows] := St2;
     End;
     St.Sort;
     For i := Grid.FixedRows To Grid.RowCount - 1 Do
     Begin
        Grid.Rows[i].Assign(TStringList(St.Objects[i - Grid.FixedRows]));
        TStringList(St.Objects[i - Grid.FixedRows]).Free;
     End;
     St.Free;
end;

Procedure Distinct(Grid : TStringGrid;CutCol : LongInt);
var
   i,j : Integer;
begin
j:=1;
with  Grid  do
begin
 for i:=2 to rowcount-1 do begin
  if Cells[CutCol,j]<>Cells[CutCol,i] then begin
//    Cells[CutCol,j+1]:=Cells[CutCol,i];
// 行単位で複写
    Rows[j+1].Assign(Rows[i]);
    j:=j+1;
  end
 end;
// 重複した行の分に行数を合わせる(不要な行を削除)
 rowcount:=j+1;
end;
end;

// テストデータ作成
procedure TForm1.Button1Click(Sender: TObject);
begin
with  StringGrid1  do
 RowCount:=6;
 Cells[1,1]:='abc';
 Cells[1,2]:='abc-2';
 Cells[1,3]:='abc-1';
 Cells[1,4]:='abc-2';
 Cells[1,5]:='abc-3';
 Cells[2,1]:='1';
 Cells[2,2]:='2';
 Cells[2,3]:='3';
 Cells[2,4]:='4';
 Cells[2,5]:='5';
end;                
end;                

// 動作テスト
procedure TForm1.Button2Click(Sender: TObject);
begin
   GridSort(StringGrid1, 1); //1カラム目でソート
   Distinct(StringGrid1, 1); //1カラム目で重複削除
end;                


UbutuでDropBoxを活用する

UbutuでDropBoxを活用するためにクライアントソフトをインストールしてみました

環境
Ubuntu 20.04.1 LTS (64 ビット)

まず、Webから入り、ログインしておく

https://www.dropbox.com/

クライアントソフトをダウンロードする
Ubuntu 14 以上 64bitを選択

https://www.dropbox.com/install-linux

ターミナルを開きダウンロードしたフォルダに移動する

cd
cd ダウンロード
ls
dropbox_2020.03.04_amd64.deb

インストールを行う

sudo dpkg -i dropbox_2020.03.04_amd64.deb

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

Lazarus Tabpageを使う

Tabpageを使って見る

機能と用途
タブにより、画面の内容の切り替えができる
プログラムの中で、タブの切り替えができる
画面遷移のように切り替えることができる
プログラムが動いていないプログラム作成の時にも
タブの切り替えができるため
BotuunやStringGridやEditなど数が多くなったときに
画面に設置することで、作成時にも整理ができる

作成(編集)時のタブの追加は
右クリックのタブの追加で行う

プログラムの中でのタブの切り替えは
TabIndexを指定することでできる

TabIndexは一番左が0となる


pageControl1.TabIndex:=1;

タブ部分を非表示にする方法は
TabVisible := False;
とする

すべてのタブを非表示にするのは
for i := 0 to PageControl1.PageCount – 1 do
PageControl1.Pages[i].TabVisible := False;

参考
//https://blog.dreamhive.co.jp/yama/2698.html

プログラム
TabSheet1の上にButton1
TabSheet2の上にButton2
TabSheet3の上にButton3
を設置

procedure TForm1.Button1Click(Sender: TObject);
begin
  pageControl1.TabIndex:=1;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  pageControl1.TabIndex:=2;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  pageControl1.TabIndex:=0;
end;      

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;