iOS, How to make the bridge with event between ObjP & delphi ? [Edit]

iOS, How to make the bridge with event in delphi ? 

I write small class ( async downloader using NSURLConnection ).
And It's works. so I want to include main program with delphi style.

But, Objective C Classes can not have published sections...

How to bond between ObjC style pascal class and delphi (FPC) with event ?
If any 

Thank a lot
Simon, Choi

>//
>//  URLDownload Object Class
>//
>unit UrlDownload;
>
>{$modeswitch ObjectiveC1}
>
>interface
>
>uses
> sysUtils,iPhoneAll;
>
>type
>  // Define Event Type
>  TXferState         = (xsStart, xsWork, xsEnd, xsErr);
>*// Delphi Style Event* 
>*TOnXferInfo = procedure (state : TXferState) of Object;*
>  // Define Protocol
>  TXferEventProtocol = objcprotocol
>   optional
>    procedure onXferEvent(state : TXferState); message 'onXferEvent:';
>  end;
>
>  // Object Class
>  TURLConnection = objcclass(NSURLConnection,TXferEventProtocol)
>    //
>    parent      : id;  
>    webData     : NSMutableData;
>    downCur     : Integer;
>    downTot     : Integer;
>    //  
>    procedure download(url : NSString); message 'download:';
>   protected
>    reqURL      : NSURL;
>    theRequest  : NSMutableURLRequest;
>   public
>
>    // Create,Destroy  
>    function  init : id; override;
>    procedure dealloc;   override;
>    // Overrider SURLConnection Funcs.
>    procedure connection_didReceiveResponse(connection : NSURLConnection; response : NSURLResponse ); override; 
>    procedure connection_didReceiveData    (connection : NSURLConnection; data     : NSData        ); override;    
>    procedure connection_didFailWithError  (connection : NSURLConnection; error    : NSError       ); override;
>    procedure connectionDidFinishLoading   (connection : NSURLConnection);                            override;  
>   *published // Error : Can't permit published in ObjP Class*
>    *// Event*
>    *property  OnXferStart : TOnXferInfo read FOnXferInfo write FOnXferInfo;*
>   end;
>
>implementation
>
>//
>function TURLConnection.init : id;
> begin
>  Result  := inherited init;
>  webData := NSMutableData.alloc.init; 
> end;
>
>//
>procedure TURLConnection.dealloc;
> begin
>  webData.release;
>  inherited dealloc;
> end;
>
>// download func.
>procedure TURLConnection.download(url : NSString); 
> begin
>  reqURL        := NSURL.urlWithString(url);
>  theRequest    := NSMutableURLRequest.requestWithURL(reqURL);
>  //
>  initWithRequest_delegate(theRequest,self);
> end;
>
>// When downloading start 
>procedure TURLConnection.connection_didReceiveResponse(connection : NSURLConnection; response : NSURLResponse );
> begin
>  // Init Status 
>  downCur := 0;
>  downTot := response.expectedContentLength;
>  webData.setLength(0);
>  //
>  NSLog(NSStr('Event:didReceiveResponse'));
>  // Make Event 
>  if parent.respondsToSelector(sel_registerName(Pchar('onXferEvent:'))) then
>   parent.onXferEvent(xsStart);
> end;
>
>// When tranfering 
>procedure TURLConnection.connection_didReceiveData (connection : NSURLConnection; data : NSData ); 
> begin 
>  //
>  inc(downCur,data.length);
>  webData.appendData(data);
>  // Make Event 
>  if parent.respondsToSelector(sel_registerName(Pchar('onXferEvent:'))) then
>   parent.onXferEvent(xsWork);  
> end;
>
>// When Downloading finished
>procedure TURLConnection.connectionDidFinishLoading (connection : NSURLConnection);
> Var
>  fileName   : NSString;
>  pathArr    : NSArray;
>  folder     : NSString;
>  filePath   : NSString;
>  fileURL    : NSURL;
>  writeError : NSError;
> begin
>  //
>  fileName   := reqURL.path.lastPathComponent;    
>  pathArr    := NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,True);
>  folder     := pathArr.objectAtIndex(0);         
>  
>  filePath   := folder.stringByAppendingPathComponent(fileName);  
>  fileURL    := NSURL.fileURLWithPath(filePath);  
>  writeError := nil;
>  // Result
>  // fileName : RADStudio_XE2_datasheet.pdf
>  // folder   : /Users/..iPhone Simulator/4.3/.../Documents/
>  // filePath : /Users/..iPhone Simulator/4.3/.../Documents/RADStudio_XE2_datasheet.pdf
>  // fileURL  : file://localhost/Users/.../RADStudio_XE2_datasheet.pdf
>
>  // Save to disk
>  webData.writeToURL_options_error(fileURL,0,@writeError);
>  webData.setLength(0);
>  //  
>  Case writeError <> nil of
>   True  : NSLog(NSStr('Event:Saving Error'));
>   False : NSLog(NSStr('Event:didFinishLoading'));
>  End;
>  // 이벤트 생성 
>  if parent.respondsToSelector(sel_registerName(Pchar('onXferEvent:'))) then
>   parent.onXferEvent(xsEnd);
> end;
>
>// OnError, 오류 발생시 
>procedure TURLConnection.connection_didFailWithError  (connection : NSURLConnection; error    : NSError       );
> begin
>  NSLog(NSStr('Event:didFailWithError'));
>  // 이벤트 생성 
>  if parent.respondsToSelector(sel_registerName(Pchar('onXferEvent:'))) then
>   parent.onXferEvent(xsErr);
> end;
>
>end.
>

Edited by: simon choi on Sep 30, 2011 1:01 AM
0
simon
9/30/2011 8:01:41 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

0 Replies
1321 Views

Similar Articles

[PageSpeed] 39

Reply:

Similar Artilces:

Delphi XE4 - Firemonkey
I have an application that runs fine on windows, however when running on iOS simulator the onKeyUp event for a TEdit control is not being fired? Please advise if this event should get fired when running on iOS? This problem occurs onKeyUp events created directly on the control and by assigning the event programatically. Running XE4 update 1 iPhoneOS6.1.sdk Minimac: OS X 10.9 XCode 5 iOS Simulator Version 7.0 - iPad Retina / iOS 7.0.3(11B508) ...

How do you rate you experience programming for IOS in Delphi/Firemonkey [Edit]
Hello: I've been taking a IOS programming course in objective-c/swift with xcode, and while doing my homework assignments I came to the conclusion that this is a very finicky environment, where very often things don't work as expected or there is always some minor UI glitch that has to be fixed or found workarounds for. Just to give you some examples (by far not an exaustive list): a UITableView doesn't align to the top when you use a navigation controller; upon selecting a row in a UITableView some buttons in the row disappear while the row is selected; specifying layout con...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Firemonkey app from Delphi XE2 -> Dropbox & iCloud [Edit]
Im developing an app for iOS and MacOS Is there any component or a way to connect to Dropbox and iCloud using Delphi XE2? > {quote:title=laureano bonilla wrote:}{quote} > Im developing an app for iOS and MacOS > > Is there any component or a way to connect to Dropbox and iCloud using Delphi XE2 For iCloud, you will need support for both iOS 5.0 and 10.7 Lion. I don't believe XE2 even supports the classes added with iOS 4.x, much less 5.0, although you can parse the iOS 5.0 UIKit and Foundation headers yourself: http://web.me.com/macpgmr/ObjP/Xcode4/iOS_5_Parsing_...

Delphi XE8 FireMonkey iOS Style problem with segmented buttons [Edit]
Hi, Going through some tutorials to get used to mobile development using FireMonkey and Delphi XE8. One of the most basic layouts tend to use the toolbar component with segmented speed buttons, and then applying the correct segmented style to each button. However, there seems to be an issue with the iOS style. [Screenshot.|https://drive.google.com/file/d/0B68Ju-patBf-RVVEMmI5UDd2cG8/view?usp=sharing] Using the "segmentedbuttonleft", "segmentedbuttonmiddle", and "segmentedbuttonright" styles is producing an extra border on the right button in iOS. It seems...

How Can I Delphi 2009 & Indy 10 TCPServer & TCPClient & Stream ? [Edit]
How can i send simple XML data from TCPClient to TCPServer and opposite. The Indy Version is the Delphi 2009 shipped version (v10). I have some XML data (you can think it as TStrings). I Can not convert the xml string to stream and send it to server then can't convert from stream sent to server to TStrings (or string) again in server (or client) side... Thanks for code snippets & answers... Edited by: Huseyin Melih Kara on Apr 27, 2009 7:59 AM Edited by: Huseyin Melih Kara on Apr 28, 2009 5:24 AM > {quote:title=Huseyin Melih Kara wrote:}{quote} > How can i send simp...

I can to install one not delphi program foir iOS into one iOS for delphi?
For example i have one programm builded as xcode for iOS, and i build one program as delphi for iOS. I want to have only one instalation, i can to add this xcode program into my delphi installer of my ios program? I can to do the same as android? how i can to to this? > {quote:title=oscar mejia wrote:}{quote} > For example i have one programm builded as xcode for iOS, and i build one program as delphi for iOS. I want to have only one instalation, i can to add this xcode program into my delphi installer of my ios program? > > I can to do the same as android? how i can to to...

Convert Delphi 7 to Delphi 2009 [Edit]
Hi! Please, I have a code done in Delphi 7... Now I want to convert Delphi 7 to Delphi 2009 but I'm having problems when compile the code. Error message: +[DCC Fatal Error] Far.dpr(9): F2063 Could not compile used unit 'System.pas'+ Please can somebody help me? Source Download (349KB): http://rapidshare.com/files/256191328/FileManager.rar.html Mirror Source Download: http://www.megaupload.com/?d=12GYLPT0 Password: delphi Thank u so much! (sorry for my bad english, it is not my native language) Edited by: loquax loquax on Jul 15, 2009 12:24 PM Sorry, bu...

New to Delphi
Hi I am new to Delphi & want to know good resources for learning to use it. Is there a list of good Delphi learning resources (books/online tutorials) somewhere? What recommendations can anyone make for someone new to Delphi (& only a hobby programmer at the moment)? A couple of weeks ago I started with DelphiXE4 trial & have Googled for a few Delphi resources but I haven't found anything very good yet for me as a beginner. I'm just struggling along trying to learn as I go! (I'm presently struggling with DragandDrop...see [http://stackoverflow.com/questions/17232...

How to make XE4 Firemonkey ios Component from native iOS UI controls ? [Edit]
Hi, I write this simple code for control volume in iOS {code} Var MPV : MPVolumeView; Procedure TForm1.SbPlayClick( Sender: TObject ); Begin MPV := TMPVolumeView.Wrap( TMPVolumeView.Alloc.InitWithFrame( CGRectMake( 20, 50, 200, 100 ) ) ); MPV.SetShowsRouteButton( True ); MPV.SetShowsVolumeSlider( True ); MPV.SetNeedsDisplay; WindowHandleToPlatform( Self.Handle ).View.AddSubview( MPV ); End; {code} MPVolumeView is a iOS UIView. with this line we can add iOS UIView elements into form, now how can add this elements into firemonkey controls ? {code} WindowHandle...

How to make XE4 Firemonkey ios Component from native iOS UI controls ? [Edit]
Hi, I write this simple code for control volume in iOS {code} Var MPV : MPVolumeView; Procedure TForm1.SbPlayClick( Sender: TObject ); Begin MPV := TMPVolumeView.Wrap( TMPVolumeView.Alloc.InitWithFrame( CGRectMake( 20, 50, 200, 100 ) ) ); MPV.SetShowsRouteButton( True ); MPV.SetShowsVolumeSlider( True ); MPV.SetNeedsDisplay; WindowHandleToPlatform( Self.Handle ).View.AddSubview( MPV ); End; {code} MPVolumeView is a iOS UIView. with this line we can add iOS UIView elements into form, now how can add this elements into firemonkey controls ? {code} WindowHandle...

How to make a procedure in Delphi? [Edit]
I want to know how to make a procedure in Delphi. I will be calling this procedure whenever value of EditBox, ComboBox and RadioButton(s) change. {code} procedure GetName(); begin if TForm1.edbName.Text <> '' then if TForm1.TComboBox.Text <> '' then if TForm1.rdbPersonal.Checked then TForm1.edbName.Text := Name1 + 'Dummy' else if TForm1.rdbCommercial.Checked then TForm1.edbName.Text := Name2 + 'Dummy' ...

TestFlight & Delphi [Edit]
Hi, Now TestFlight is integrated into itunesconnect. I would like to use it for beta testing. I succeed to enable it, invite some internal testers, and download the app on iPhone using TestFlight app. My issue is that my app crashes at starting (splash). I added this on the entitlements : {code} <key>beta-reports-active</key> <true/> <key>get-task-allow</key> <false/> {code} Is it correct? Is there any other thing to? Is someone here use TestFlight with XE project? Is it possible with XE5 (SDK 7.1)? Thanks in advance ;) ...

Code works in Delphi 7 but not in Delphi 2010 [Edit]
hello, i have a procedure that open's a file by passing the file name as the parameter to the executable. something like this {code} C : \ P r o g r a m F i l e s \ Da c k e r \ D r a c k e r . e x e " G : \ D E l p h i 7 \ D e l p h i 7 A p p _ l o g . t " {code} The source code is {code} procedure OpenFileWithExe var hReg: HKEY; Ret: Longint; RegDataType, RegDataSize: DWORD; CmdLine: array [0..560] of Char; Len: Integer; SInfo: TStartupInfo; PInfo: TProcessInformation; begin Ret := windows.RegOpenKeyEx(HKEY_CURRENT_USER, ...

Web resources about - iOS, How to make the bridge with event between ObjP & delphi ? [Edit] - embarcadero.delphi.firemonkey

Finally, there's a 'Fantastic Beasts and Where to Find Them' trailer
Space movie? What space movie? See also: Here's the magical plot of 'Fantastic Beasts and Where to Find Them' If you prefer wands to warp speed, ...

Gangster shot dead by firearms officer was 'holding a fake gun': Police officer could now face murder ...
Jermaine Baker, 28, (pictured) a father of two from Tottenham, was killed by police as he sat in a black Audi on Friday and police believe he ...

This drinking game will help you survive your holiday party hell
It’s that time of year again. The time when we are forced to leave our warm, crackling computer screens, and head out to some stranger’s holiday ...

FAA finally issues ruling: Registration is a go for drone pilots
No license requirement, but don't fly those Christmas gifts without registering

Seattle lets Uber drivers join union in US first
Seattle has passed a measure allowing drivers of smartphone-based taxi companies like Uber and Lyft to unionize over pay and other working conditions, ...

New research shows Earth’s tilt influences climate change
From the LOUISIANA STATE UNIVERSITY and the department of tilt-a-whirl, comes this Milankovitch moment. LSU paleoclimatologist Kristine DeLong ...

Cosby sues seven accusers for defamation, seeks damages and retractions
wtkr.com Cosby sues seven accusers for defamation, seeks damages and retractions wtkr.com Bill Cosby has struck back against some of the dozens ...

Kim Kardashian Having Another Baby Could Be Deadly
Kim Kardashian and Kanye West just had their second child and it sounds like it will be the last. Kim gave birth to her son Saint West recently ...

Newtown priest issues emotional plea on anniversary of Sandy Hook shooting to ...
New York Daily News Newtown priest issues emotional plea on anniversary of Sandy Hook shooting to ... New York Daily News Three years after ...

Google Maps Update For iOS Brings Offline Navigation
Recently an update to Google Maps for iOS introduced the gas price feature . Basically this allows users to find out the prices of gas that different ...

Resources last updated: 12/15/2015 1:21:40 PM