掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
DLL内でEXE側のDBGridで表示されているのをExcel表示するには? (ID:38444)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
DLL内でExe側のDBGridに表示されたデータをExcelに表示させたいのですが、 エラーになる部分があるので教えてください。 DLL内に関数を作成し、引数でDBGridを渡しています。 function OutExcelFromDbGrid(piDBGrid: TDBGrid; piTitle: Pchar; piExcel: boolean): boolean; stdcall; const HeaderCol = 1; HeaderRow = 1; MeisaiHRow = 3; MeisaiCol = 1; MeisaiRow = 4; ExtKeyWard = 'test'; var i, j, k, m, n: integer; strText : string; Excel : olevariant; ADataSet : TDataSet; BookMark : TBookmark; TFT : TFieldType; rRect : TRect; iRight : integer; intKeyWard : integer; //a : String; begin strText := ''; intKeyWard := -1; // DBGridに関連付けされているDataSetを変数に代入 ADataSet := piDBGrid.DataSource.DataSet; BookMark := ADataSet.GetBookmark; if not ADataSet.Active then begin ADataSet.Active := True; end; // DBGridに表示されているフィールドの列名を取得し、文字列に代入 j := piDBGrid.Columns.Count - 1; for i := 0 to j do begin if not piDBGrid.Columns[i].Visible then begin Continue; end; //非表示列は除外 strText := strText + piDBGrid.Columns[i].Title.Caption; if i < j then begin strText := strText + #9; end; if piDBGrid.Columns[i].Title.Caption = ExtKeyWard then begin intKeyWard := i; end; end; // DBGridに表示されているデータを取得し、文字列に代入 strText := strText + #13#10; Screen.Cursor := crSQLWait; ADataSet.DisableControls; try ADataSet.First; while not ADataSet.EOF do begin for i := 0 to j do begin if not piDBGrid.Columns[i].Visible then begin Continue; end; //非表示列は除外 //a := piDBGrid.Columns[i].Field.DisplayText; //strText := strText + a; //showmessage(piDBGrid.Columns[i].Field.DisplayText); strText := strText + piDBGrid.Columns[i].Field.DisplayText; //☆☆☆ if i < j then begin strText := strText + #9; end; end; ADataSet.Next; strText := strText + #13#10; end; finally ADataSet.EnableControls; Screen.Cursor := crDefault; ADataSet.GotoBookmark(Bookmark); ADataSet.FreeBookmark(Bookmark); end; ・ ・ ・ ☆☆☆の部分でGridのデータを文字列に代入しているのですが 22列中13列目で文字列に代入せずにfinally処理が走ってしまいます。 またFinally処理のFreeBookmark部分でエラーになってしまいます。 エラーは「アドレス00000000のアドレス00000000でエラーが発生しました」です。 試しでFinallyをExceptにしてみたらエラーはでませんでした。 (それも意味がわからないのですが…) まず、なぜ22列あるのに13列でFinally処理に行ってしまうのかが知りたいです。 よろしくお願いします。
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.