2016-11-16 28 views
-1

我注意到當我使用OnDragDrop事件和OnDragOver事件時出現錯誤。看看這段代碼:Firemonkey拖放可能的錯誤

procedure TForm1.Button1DragDrop(Sender: TObject; const [Ref] Data: TDragObject; 
    const [Ref] Point: TPointF); 
var t,d: TButton; 
begin 

T := TButton(Sender); 
D := TButton(Data.Source); 
T.data := T.data + D.data; 
Score(T.data); 
D.data := 0; 
T.isOk := true; 

end; 

procedure TForm1.Button1DragOver(Sender: TObject; const [Ref] Data: TDragObject; 
    const [Ref] Point: TPointF; var Operation: TDragOperation); 
begin 

if ((Sender is TButton) and (Data.Source is TButton) and not(Sender = Data.Source) 
    and (TButton(Sender).Text = TButton(Data.Source).Text) and (TButton(Data.Source).Text <> '')) then 
    begin 
    operation := TDragOperation.Move; 
    end 
else 
    begin 
    operation := TDragOperation.None; 
    end; 

end; 

這個代碼與您可以在下面的圖中看到的形式:

enter image description here

這是一個網格佈局與一些按鈕內; Button1是左上角的按鈕,所有其他按鈕都有指向Button1事件的事件OnDragDropOnDragOver。例如look

當我在Windows(目標平臺win32位)下運行該程序時,我可以使用光標和鼠標將網格中的按鈕拖放到網格中。當我移動到android時出現問題,因爲在我的手機上我無法拖放按鈕。任何想法?

這是一個使用Firemonkey構建的多設備應用程序。我在想,我必須爲每個按鈕聲明DragDrop和DragOver事件,而不是引用Button1。這可能嗎?

+1

AFAIK,IFMXDragDropService僅適用於Windows和Mac。 –

回答

3

這不是一個錯誤,你可以在文檔中找到原因here; DragDropService沒有在android平臺上實現。

可以使用IFMXDragDropService在Windows和OS X

雙方如果你想測試我建議你用這一行試試:

if TPlatformServices.Current.SupportsPlatformService(IFMXDragDropService) then 
begin 
    //test code 
end; 

爲了確保您可以使用IFMXDragDropService服務,首先測試它是否受支持。