I need to open a webpage with safari in my iOS application.
With XE2 there was iphoneall unit, which exposed UIApplication. XE4 doesn't use FPC anymore, so I can't use that.
Embarcadero documentation
says I can use SDKs only with C++ or using delphi interfaces (and still, macapi is for OSX only, not iOS). So, it seems that there is no interface for UIKit framework?!
Another solution I tried was:
_system('open http://www.google.com');
But that had no affect at all!
Is there any other ways to open urls or am I out of luck to accomplish it?
I know there is TWebBrowser component for ios, but I wouldn't want to take that road just to display a webpage.
By chance, someone at Embarcadero posted a code snippet to do exactly this two days ago.
If you are using XE4, look in the Samples, and you can find one (sorry, not sure of the name) where the final code is:
OpenURL('http://www.embarcadero.com');
This uses the XE4 FireMonkey framework and a class helper written by David Clegg, available in the sample.
If you are using an older version of FireMonkey, you can use the rather more cumbersome code:
function SharedApplication: UIApplication;
begin
Result := TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
SharedApplication.openURL(TNSURL.Wrap(TNSURL.OCClass.URLWithString(NSSTR(PChar(String('http://www.embarcadero.com'))))));
end;
(Attribution: Code snippets all copied from the linked blog post.)
There is also a very old forum post from the early days of FireMonkey showing how to tackle these problems in general (basically, string <-> NSString <-> NSURL), and while it's a bit out of date - as you can see by the above code, FireMonkey has matured greatly - it may give some insight into the underlying reason for the code.
Related
I want to be able to see how one calls the Windows API in Delphi. Recently I had a question about GetProcessorAffinity and the Delphi declaration was posted as part of the answer. I would like to know how to find that kind of information.
There is no function named GetProcessorAffinity. Probably you mean GetProcessAffinityMask. That function is declared in the RTL unit Winapi.Windows. The source file for this is supplied with Delphi. You can use CTRL + click to navigate to the declaration of any function.
If you do so with GetProcessorAffinity then you will be taken to its implementation in Winapi.Windows. Now, that implementation looks like this:
function GetProcessAffinityMask; external kernel32 name 'GetProcessAffinityMask';
This is not terribly useful, but the information you are looking for is close by. Now that you are in the file which contains the implementation, you can find the declaration. Move to the top of the file and search for GetProcessAffinityMask. That will take you here:
function GetProcessAffinityMask(hProcess: THandle;
var lpProcessAffinityMask, lpSystemAffinityMask: DWORD_PTR): BOOL; stdcall;
That's the information that you need.
Many of the Windows API functions, but not all, are declared in Winapi.Windows. But the process described above will take you to the right file in any case.
The other technique that is useful is to search within files. From the IDE Search menu select Find in Files. Configure the dialog like this:
Note that you'll need to use a path suitable to your version of Delphi. For instance, my example is from XE7, which is version 15, but you have XE5 which is version 12.
Delphi comes by default with some Windows API's in different units (a lot of them in the (WinApi.)Windows unit.
A more complete translation of the Windows API headers can be found in the Delphi Jedi Apilib project.
In Delphi XE2, there was an IDE feature which allowed me to create in-line XML code documentation (following Microsoft standards) in an editor window. It would describe each class, type, method, etc. in the interface section of a unit. However, in Delphi XE7, I cannot find it. I've done some searching, but as you can imagine, Delphi XE7 XML Code Documentation does not return the results I'm looking for.
In XE2, I remember the shortcut to toggle this window was either CTRL + SHIFT + D or CTRL + ALT + D. Neither of them do anything in XE7. I know I could manually write this myself, but that's a bit inconvenient. All I can find in the documentation is how to write the text yourself, and nothing about the editor window I was used to in XE2. I never installed any Delphi add-ons other than what came with Delphi itself (besides IDE Fix Pack).
Where can I find this feature in Delphi XE7 Enterprise? Or was it removed for some reason?
The feature you are describing is not directly implemented into Delphi but comes as third party addon that does integrate into Delphi. It is called Documentation Insight.
http://www.devjetsoftware.com/products/documentation-insight/
Documentation insight had come as free third party addon till Delphi XE6 when it was suposingly removed. Don't ask me why as I don't know.
So I'm afraid that you will have to buy this third party IDE extention now.
EDIT: Or you could use newest version of Delphi for development of your program and older version of Delphi like XE2 to generate documentation.
I am using Delphi XE. I have come across a memory leak problem using Delphi Soap. It turns out to be due to a missing .Free call in TWSDLLookup.Destroy, as described in QC 91160
The problem that I have is the described work-around, which is simply to add FLookup.Free to the TWSDLLookup.Destroy method.
I don't want to change the Delphi source, so I tried copying the unit to my project folder, making the change and recompiling, as described here in Tom's answer. The problem with this technique is that it apparently only works if you also recompile all the dependent units. I have tried copying just WSDLLookup.pas to my project directory and I get a Stackoverflow error. I'm not familiar with Web Services / SOAP so I don't know what other units I should copy over if I do use this technique.
Rob Kennedy's answer on the same page describes a different technique involving code hooking - but it doesn't seem to apply to object methods. I have done as he suggests and downloaded the free code for the TNT Unicode controls and located the relevant procedures, but I have been unable to find info on how to hook an object's methods - if indeed this is possible. If I could do this, I would then hook TWSDLLookup.Destroy and add the FLookup.Free call.
Any ideas for how to fix this will be much appreciated. I'm a bit of a newbie programmer so I'm hoping that I've missed something obvious?
What you are trying to do does in fact work fine. I tested it out myself. Here's the project file I used:
program WSDLLookupTest;
{$APPTYPE CONSOLE}
uses
WSDLLookup in 'WSDLLookup.pas';
var
intf: IInterface;
begin
intf := GetWSDLLookup as IInterface;
end.
I made a copy of the WSDLLookup.pas file and placed it in the same directory as the .dpr file. Then, in the copy rather than the original, I modified TWSDLLookup.Destroy.
destructor TWSDLLookup.Destroy;
begin
Beep;
ClearWSDLLookup;
FLookup.Free;
inherited;
end;
I added the Beep to prove to myself that this code was indeed being executed.
In your position I would definitely use this solution instead of attempting code hooks. And of course the other simple solution is to upgrade to a later Delphi version.
One thing to be careful of is to remember to remove the modified unit when you do upgrade. The leak was fixed in XE2.
Why isn't anyone developing QT bindings for Delphi.
In the past we had QT 2.x integrated as CLX in Delphi.
I really hate the CLX wrappers since they were buggy and hard to extend.
But why isn't anyone making an API list of external DLL calls to use (the same way JCL wraps the Windows API).
Is it so hard to code such API function mapping? Or maybe the QT classes cannot be exposed to non-C callers?
Any hint in this direction is welcome.
qtintf.dll seems to be the flat API DLL you're looking for and Qt.pas the corresponding import unit.
I recommend you wait for VCL+, that is the Qt binding coming with the next version of Delphi.
The problem is that Qt is heavily macro-based and C++ based. So the Qt "flat API" is quite verbose and big. I wonder how EMB will create its own VCL+ binding, but I'll definitively wait for their implementation for using Qt on any Delphi project.
If you can't wait, and really want cross-platform User Interface (with Mac O$ support), I recommend using http://www.twinforms.com/products/wxformsdelphi and not Qt. It relies on a separate DLL, but it's easier to develop, and well maintained/documented.
I managed to port the qt4.pas from
http://users.telenet.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html.
It is originally written for Lazarus but I managed to port it to Delphi.
One must do the following
declare
type
PUInt = ^Integer;
PTRUINT = PUInt;
PtrInt = ^Integer;
PPtrInt = ^PtrInt;
comment out all calls with "qword" paramters since quad-words are not supported in Delphi
comment out "{$mode objfpc}{$H+}" since this is Lazarus stuff
replace all "cdecl; external" with "cdecl; overload; external"
Than the demos can be compiled and run just fine with Delphi.
From what I've heard, apparently the cross-platform component library for Delphi XE2 (version due out next year) will be QT based, sorta like CLX only it should actually work right.
Has anyone come across a framework or library for Delphi to simplify the generation of x86 code? I am not looking for an assembler, but rather a framework that abstracts the code generation process above the low level bits and bytes. Ideally I would like to build on top of an existing library or framework rather than hardcode the logic on a case by case basis.
The initial usage will be to generate small code stubs at runtime similar to the way Delphi dispatches SOAP requests. If I cannot find something I will likely roll my own, but I would hate to reinvent the wheel. Something in "C" might me interesting provided the license will permit translation and use in commercial and open source projects.
Update:
Here is some more context: What I am working toward is runtime implementation of interfaces and/or classes as part of a persistence framework. Something sort of like Java annotation driven persistence (JPA/EJB3) except with a distinctly Delphi flavor. The invocation target is a modular/extensible framework which will implement a generalized persistence model. I need to dispatch and hook method calls based on RTTI and an annotation/attribute model (something similar to InstantObjects metadata) in a very dynamic and fluid manner.
Thanks,
David
The more I have thought about your question. I am not sure if all you trying to just do Dynamic Method Invocation. Even though your asking about generating x86 code.
There are several techiniques that do this.
If you know the signature of the method in question you can do it easily by using a
TMethod and setting the method address and data.
procedure TForm8.Button1Click(Sender: TObject);
begin
Showmessage('Hello1');
end;
procedure TForm8.Button2Click(Sender: TObject);
var
M : TMethod;
begin
M.Code := MethodAddress('Button1Click');
M.Data := Self;
TNotifyEvent(M)(self);
end;
If you don't know the method signature you can write the class with {$METHODINFO ON}
Then use the functionality in ObjAuto.pas to invoke the method.
I have an example in my RTTI Presentation code from DelphiLive on how to do that.
According to features of PaxCompiler, you can create stand alone executable files.
Very spectulative answer:
Something like LLVM? I am not sure if it can be used from delphi or not, but you should be able to create dll's wth it.
Logically you would simply generate delphi code, compile to a DLL/BPL by cmdline compiler and then dyn load that one?
Unfortunately Delphi Explorer doesn't come with the cmdline compiler though. And your main binary would also have to be in Delphi Explorer (or at least in D2006 if that is binary compatible enough)
Any mix of Delphi versions (or Free Pascal) will probably not work on the package or HLL level, only at basic procedural DLL level.
I just found an interesting framework that does much of what I was looking for when I originally posted the question. A little late for my purposes, but thought someone else might find this useful:
DAsmJit a Delphi port of the asmjit project