How can I use the IconField argument in LoadFromDataSet function of TGMMarker (GMLIB) - gmlib

I am using loadfromdataset function of TGMMarker object in GMLib, but I can't get the IconField to work.
I have a BLOB field with a png image to use as a Icon. I load the very same image file directly from the
folder with no problems, but when I try to do it with the IconField argument it gives error.
Here's the code
inherited;
GMMap1.Active := True;
GMMarker1.LoadFromDataSet(Dscameras.DataSet,'Latitude','Longitude',
'Descrição','Distintivo');
Gives this error :"Erro de Script" "Constante de cadeia não finalizada"

The minimum code is:
procedure TForm1.FormCreate(Sender: TObject);
begin
ClientDataSet1.LoadFromFile('markers.xml');
GMMap1.Active := True;
end;
procedure TForm1.GMMap1AfterPageLoaded(Sender: TObject; First: Boolean);
begin
if First then
begin
GMMap1.DoMap;
GMMarker1.LoadFromDataSet(ClientDataSet1, 'lat', 'lng', 'title');
GMMarker1.ZoomToPoints;
end;
end;

Related

How can I prevent that a LCL defined focused empty ListBox implementing some kind of search field

I'm working with
FreePascal 3.2.0,
Lazarus 2.0.12,
GTK2 GUI backend
under Ubuntu Linux 18.04.
I have a strange behavior of a TListBox component.
When I focus a empty ListBox by clicking (SetFocus) and
press the [space] key,
some kind of Edit or SearchField appears (..see image below).
The field vanishes after a short period (3 s).
How can I switch off this "feature".
My current work around is to use a handler for the onEnter event to take away the ListBox focus (full code example see below).
procedure TFrmMain.lbxTestEnter(Sender: TObject);
begin
if mUseWorkAround then begin
if LbxTest.Items.Count = 0 then begin
PnlButton.SetFocus;
exit;
end;
end;
end;
I'm not sure if this is the right way.
Full Code Example:
unit UFrmTestListBox;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls;
const
PNL_MESSAGE = 'WORK AROUND IS %sACTIVE! ';
type
{ TFrmMain }
TFrmMain = class(TForm)
BtnToggle: TButton;
GbxList: TGroupBox;
GbxLog: TGroupBox;
LbxTest: TListBox;
MmLog: TMemo;
PnlButton: TPanel;
SplMain: TSplitter;
procedure BtnToggleClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure lbxTestEnter(Sender: TObject);
private
mUseWorkAround: Boolean;
mCounter: Integer;
procedure OutLn(S:String);
public
end;
var
FrmMain: TFrmMain;
implementation
{$R *.lfm}
procedure TFrmMain.FormCreate(Sender: TObject);
begin
mUseWorkAround:= false;
mCounter := 0;
PnlButton.Caption:=Format(PNL_MESSAGE,['NOT ']);
end;
procedure TFrmMain.lbxTestEnter(Sender: TObject);
begin
inc(mCounter);
OutLn('');
OutLn(Format('--- %d -----------------------', [mCounter]));
OutLn('ListBox onEnter event');
if mUseWorkAround then begin
OutLn('Work around is active!');
if LbxTest.Items.Count = 0 then begin
OutLn('ListBox is empty, change focus to the button panel.');
PnlButton.SetFocus;
exit;
end;
end else begin
OutLn('Work around NOT active!');
OutLn('ListBox is empty, press [SPACE] & EditField appears.')
end;
end;
procedure TFrmMain.BtnToggleClick(Sender: TObject);
begin
mUseWorkAround:=not mUseWorkAround;
if mUseWorkAround then
PnlButton.Caption:=Format(PNL_MESSAGE,[''])
else
PnlButton.Caption:=Format(PNL_MESSAGE,['NOT ']);
end;
procedure TFrmMain.OutLn(S:String);
begin
MmLog.Lines.BeginUpdate;
MmLog.Lines.Append(S);
MmLog.Lines.EndUpdate;
MmLog.SelStart := Length(MmLog.Lines.Text);
end;
end.

GMLib MegaDemo.exe Won't load

The map won't load anymore on the megademo.exe.
The problem start when i put: GMMap1.Active := True;
Thanks for the help.
try this
var
FMapLoaded: boolean;
procedure TMainForm.GMMapAfterPageLoaded(Sender: TObject;
First: Boolean);
begin
inherited;
if First and not FMapLoaded then
begin
GMMap.DoMap;
FMapLoaded := True;
end;
end;
To solve this problem, you must to change the method TGMMap.DocumentComplete from GMMapVCL unit with this
before
if (pDisp = CurDispatch) then
after
if not FDocLoaded and (pDisp = CurDispatch) then

DSiWin32.DSiGetHtmlFormatFromClipboard not working?

I am trying to use the DSiGetHtmlFormatFromClipboard function from the well known DSiWin32 library.
Edit: There is a much newer version of DSIWin32.pas 1.94 from 2016-10-19 which is contained in the current version of OmniThreadLibrary_3.07.1. The one I've linked to in the first line of my question is much older: 1.66 from 2012-04-20. However, also in this newer version of DSIWin32.pas the function DSiGetHtmlFormatFromClipboard does not work although I've made sure that no other clipboard programs are running.
So I put some text on the clipboard which includes the HTML format e.g. by copying some text from Chrome web-browser.
And then I use this code to get the HTML format from the clipboard:
if DSiWin32.DSiIsHtmlFormatOnClipboard then
begin
CodeSite.Send('HTML-Format string:', DSiWin32.DSiGetHtmlFormatFromClipboard);
end;
While the DSiIsHtmlFormatOnClipboard function does work (it gives back True if there is HTML Format on the clipboard and gives back False if there is no HTML Format on the clipboard), the DSiGetHtmlFormatFromClipboard function always gives back an empty string although there is HTML Format in the clipboard:
So I debugged function DSiGetHtmlFormatFromClipboard: string; in DSiWin32.pas:
On this line:
hClipData := GetClipboardData(GCF_HTML);
hClipData is always 0, so the following code is not executed.
GetClipboardData is a function from Winapi.Windows and according to MSDN documentation:
Retrieves data from the clipboard in a specified format. The clipboard
must have been opened previously.
Which is the case in the DSiWin32 code.
So why does the DSiGetHtmlFormatFromClipboard always give back an empty string?
OS: Windows 7 x64
GetLastError retrieved immediately after the line hClipData := GetClipboardData(GCF_HTML);:
ERROR_CLIPBOARD_NOT_OPEN 1418 (0x58A) Thread does not have a
clipboard open.
This is strange because the preceding line is: Win32Check(OpenClipboard(0)); and it does not fail.
Here is the relevant parts of the MCVE:
var
GCF_HTML: UINT;
function DSiIsHtmlFormatOnClipboard: boolean;
begin
Result := IsClipboardFormatAvailable(GCF_HTML);
end; { DSiIsHtmlFormatOnClipboard }
function DSiGetHtmlFormatFromClipboard: string;
var
hClipData : THandle;
idxEndFragment : integer;
idxStartFragment: integer;
pClipData : PChar;
begin
Result := '';
if DSiIsHtmlFormatOnClipboard then
begin
Win32Check(OpenClipboard(0));
try
hClipData := GetClipboardData(GCF_HTML);
if hClipData = 0 then
RaiseLastOSError;
pClipData := GlobalLock(hClipData);
Win32Check(assigned(pClipData));
try
idxStartFragment := Pos('<!--StartFragment-->', pClipData); // len = 20
idxEndFragment := Pos('<!--EndFragment-->', pClipData);
if (idxStartFragment >= 0) and (idxEndFragment >= idxStartFragment) then
Result := Copy(pClipData, idxStartFragment + 20, idxEndFragment - idxStartFragment - 20);
finally GlobalUnlock(hClipData); end;
finally Win32Check(CloseClipboard); end;
end;
end; { DSiGetHtmlFormatFromClipboard }
procedure TForm1.Button1Click(Sender: TObject);
begin
if DSiIsHtmlFormatOnClipboard then
ShowMessage(DSiGetHtmlFormatFromClipboard)
else
ShowMessage('No HTML Format on Clipboard');
end;
initialization
GCF_HTML := RegisterClipboardFormat('HTML Format');
end.

Pascal : External File Can't be updated

I have an issue on rewriting my .txt file, did I made some mistake? The program run smoothly though. This is a piece of my library.
//global variable
uses utheatre;
var loadUDT:TheatreUDT;
//utheatre library
type
TheatreUDT = record
Member:text;
end;
procedure load_main(var loadUDT : TheatreUDT);
begin
load_Member(loadUDT.Member);
end;
procedure load_Member(var Member:text);
begin
assign (Member,'Data/Member.txt');
end;
procedure regis(var loadUDT:TheatreUDT);
var
s:string;
begin
rewrite(loadUDT.Member);
write('> Input Username : ');
readln(s);
write(loadUDT.Member,s);
write(loadUDT.Member,' | ');
write('> Input Password : ');
readln(s);
write(loadUDT.Member,s);
writeln(loadUDT.Member,' | 100000');
writeln('> Registration Successful');
end;
procedure exit(var loadUDT:TheatreUDT; var bool_main:boolean);
begin
close(loadUDT.Member);
bool_main := False;
end;
I expected the output inside my notepad will be
username | password | 100000
but it seems that the Member.txt is not updated. Thanks before.
EDIT : This is My Main Program
begin
bool_main := True;
while(bool_main) do begin
write('> ');
readln(input_main);
case input_main of
'load' : load_main(loadUDT);
'register' : regis(loadUDT);
'exit' : exit();
end;
end;
end.
N.B. I found out that when I add "close(loadUDT.Member)" inside my "regis procedure", it worked, however it didn't work when i insert the "close(loadUDT.Member)" inside the "exit procedure". Any ideas why? Thanks again before.
Nevermind, I found the answer already. exit() is reserved. Sorry Guys.
N.B. Thanks to #gammatester

How to call the OnChange event of "Select" ? (Delphi - WebBrowser)

I'm using Delphi and WebBrowser componenet to navigate a html page . the page have a Combobox . is there any way to call the OnChange event ?
The ComboBox is like this :
<select name="comboname" onchange="Some Javascript codes">
Also , i have used this code :
function TFrmMain.SetComboboxValue(WB: TEmbeddedWB;
SelectName, ItemName: string): Boolean;
var
iForms, iFormItems, iSelectItems: Word;
FormItem: OleVariant;
begin
Result := false;
for iForms := 0 to WB.OleObject.Document.Forms.length - 1 do
begin
FormItem := WB.OleObject.Document.Forms.item(iForms);
for iFormItems := 0 to FormItem.length - 1 do
begin
if (FormItem.item(iFormItems). type = 'select-one') and SameText
(FormItem.item(iFormItems).Name, SelectName) then
begin
for iSelectItems := 0 to FormItem.item(iFormItems).Options.length - 1 do
begin
if SameText(FormItem.item(iFormItems).Options.item(iSelectItems)
.Text, ItemName) then
begin
FormItem.item(iFormItems).SelectedIndex := iSelectItems;
Result := true;
Break;
end;
end;
end;
end;
end;
end;
But it change the value only.
to execute the onchange event you can use the execScript method
check this sample
uses
MSHTML;
var
Doc: IHTMLDocument2;
HTMLWindow: IHTMLWindow2;
begin
Doc := WebBrowser1.Document as IHTMLDocument2;
if not Assigned(Doc) then
Exit;
HTMLWindow := Doc.parentWindow;
if not Assigned(HTMLWindow) then
Exit;
HTMLWindow.execScript('yourfunctioname()', 'JavaScript');
end;
for more info check this excellent article
How to call JavaScript functions in a TWebBrowser from Delphi
Inspired by the response. NET have been using the structures below:
FrameSet Document Elements Item Name Value Change ;
EWB.OleObject.Document.Frames.Item('mainFrame').Document.Forms.Item('invoiceForm').Elements.Item('inputname').Value:= '123456';
or
FrameSet Document Elements Items Lenth;
EWB.OleObject.Document.Forms.Item('invoiceForm').Elements.Length;