Created
February 8, 2018 10:04
-
-
Save freeonterminate/b8e579da4b8897575873728f812d6e35 to your computer and use it in GitHub Desktop.
XE5 TStringGrid でヘッダをクリックされたイベントを取得するサンプルコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
* XE5 TStringGrid でヘッダをクリックされたイベントを取得するサンプルコード | |
* | |
* Copyright (c) 2018 HOSOKAWA Jun. | |
* | |
* HOW TO USE: | |
* 1. Add XE5.Grid.Helper to uses block. | |
* 2. Call StringGrid.Header[Column].OnXXX | |
* | |
* EXAMPLE: | |
* uses | |
* XE5.Grid.Helper; | |
* | |
* procedure TForm1.FormActivate(Sender: TObject); | |
* begin | |
* StringGrid1.Header[StringColumn1].OnMouseDown := HeaderMouseDown; | |
* end; | |
* | |
* procedure TForm1.HeaderMouseDown(Sender: TObject; Button: TMouseButton; | |
* Shift: TShiftState; X, Y: Single); | |
* begin | |
* ShowMessage('ok'); | |
* end; | |
* | |
* LICENSE: | |
* 本ソフトウェアは「現状のまま」で、明示であるか暗黙であるかを問わず、 | |
* 何らの保証もなく提供されます。 | |
* 本ソフトウェアの使用によって生じるいかなる損害についても、 | |
* 作者は一切の責任を負わないものとします。 | |
* | |
* 以下の制限に従う限り、商用アプリケーションを含めて、本ソフトウェアを | |
* 任意の目的に使用し、自由に改変して再頒布することをすべての人に許可します。 | |
* | |
* 1. 本ソフトウェアの出自について虚偽の表示をしてはなりません。 | |
* あなたがオリジナルのソフトウェアを作成したと主張してはなりません。 | |
* あなたが本ソフトウェアを製品内で使用する場合、製品の文書に謝辞を入れて | |
* いただければ幸いですが、必須ではありません。 | |
* | |
* 2. ソースを変更した場合は、そのことを明示しなければなりません。 | |
* オリジナルのソフトウェアであるという虚偽の表示をしてはなりません。 | |
* | |
* 3. ソースの頒布物から、この表示を削除したり、表示の内容を変更したりしては | |
* なりません。 | |
* | |
* This software is provided 'as-is', without any express or implied warranty. | |
* In no event will the authors be held liable for any damages arising from | |
* the use of this software. | |
* | |
* Permission is granted to anyone to use this software for any purpose, | |
* including commercial applications, and to alter it and redistribute | |
* it freely, subject to the following restrictions: | |
* | |
* 1. The origin of this software must not be misrepresented; | |
* you must not claim that you wrote the original software. | |
* If you use this software in a product, an acknowledgment in the product | |
* documentation would be appreciated but is not required. | |
* | |
* 2. Altered source versions must be plainly marked as such, | |
* and must not be misrepresented as being the original software. | |
* | |
* 3. This notice may not be removed or altered from any source distribution. | |
*) | |
unit XE5.Grid.Helper; | |
interface | |
uses | |
System.Classes, FMX.Grid, FMX.Header; | |
type | |
TXE5StringGridHelper = class helper for TStringGrid | |
private | |
function GetHeader(const Column: TColumn): THeaderItem; | |
public | |
property Header[const Column: TColumn]: THeaderItem read GetHeader; | |
end; | |
implementation | |
uses | |
System.UITypes, System.Rtti, FMX.Types; | |
{ TXE5GridHelper } | |
function TXE5StringGridHelper.GetHeader(const Column: TColumn): THeaderItem; | |
var | |
RttiType: TRttiType; | |
RttiField: TRttiField; | |
Header: THeader; | |
Item: THeaderItem; | |
i: Integer; | |
begin | |
Result := nil; | |
RttiType := SharedContext.GetType(TGrid); | |
if RttiType = nil then | |
Exit; | |
RttiField := RttiType.GetField('FHeader'); | |
if (RttiField = nil) then | |
Exit; | |
Header := RttiField.GetValue(Self).AsType<THeader>; | |
for i := 0 to Header.Count - 1 do | |
begin | |
Item := Header.Items[i]; | |
RttiType := SharedContext.GetType(Item.ClassType); | |
if RttiType = nil then | |
Continue; | |
RttiField := RttiType.GetField('FColumn'); | |
if RttiField = nil then | |
Continue; | |
if (RttiField.GetValue(Item).AsObject = Column) then | |
begin | |
Result := Item; | |
Result.DragMode := TDragMode.dmManual; | |
Break; | |
end; | |
end; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment