How can i change adsense code TWebbrowser object after document complete
i try change div innerhtml but i cant my see adsense commercial how can do this
my code block
doc := ie.Document as IHTMLDocument3;
doc2 := ie.Document as IHTMLDocument2;
di := doc.getElementById('aliveli') as IHTMLElement;
s := tstringlist.Create;
s.Add('<script type="text/javascript"><!--');
s.Add('google_ad_client = "pub-8340139631405508";');
s.Add('/* 120x240, oluşturulma 28.10.2009 */');
s.Add('google_ad_slot = "8877320187";');
s.Add('google_ad_width = 468;');
s.Add('google_ad_height = 15;');
s.Add('//-->');
s.Add('</script>');
s.Add('<script type="text/javascript"');
s.Add('src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
s.Add('</script>');
s.Add('');
doc2.body.innerHTML := s.text;
Try using di.innerHTML instead of doc2.body.innerHTML.
Related
I want to use the MSHTML interfaces IHTMLDocument2, IHTMLElement2, IHTMLElementCollection, etc with TWebBrowser.
In Document := WebBrowser.Document as IHTMLDocument2; when TWebbrowser.SelectedEngine = IEOnly then everything is fine.
But, when I changed the property TWebBrowser.SelectedEngine = EdgeOnly or EdgeIfAvailable then WebBrowser.Document is nil.
How can I fix this?
i used Delphi XE7 and DevExpress component, i need to create dxTileBarItem at runtime and add this to my dxTileBar but i cant.
var
//Tile4:TdxTileControlItem;
Tile4:TdxTileBarItem;
begin
Tile4 := TdxTileBarItem.Create(dxTileBar1);
Tile4.Name := 'Tile4';
Tile4.GroupIndex := 0;
Tile4.IndexInGroup := 3;
what is my mistake?
then i want to store a form object in manually created dxTileItem and call each from on OnTileClick such as ListBox, what do i should?
You can use the CreateItem method, for example:
var
MyTile: TdxTileBarItem;
begin
MyTile := dxTileBar1.CreateItem(tbisRegular);
MyTile.Name := 'My Tile';
...
end;
Or you can follow quite common pattern used by Delphi controls, add the item to the control's Items collection, for example:
var
MyTile: TdxTileBarItem;
begin
dxTileBar1.BeginUpdate;
try
MyTile := TdxTileBarItem(dxTileBar1.Items.Add);
MyTile.Name := 'My Tile';
...
finally
dxTileBar1.EndUpdate;
end;
MyTile.MakeVisible;
end;
This question is related to: Which is the best way to load a string (HTML code) in TWebBrowser?
Iam trying to change font in TWebBrowser with doc.body.style.fontFamily but nothing happens. The font is still TimesNewRoman.
procedure THTMLEdit.SetHtmlCode(CONST HTMLCode: string);
VAR
Doc: Variant;
begin
if NOT Assigned(wbBrowser.Document)
then wbBrowser.Navigate('about:blank');
WHILE wbBrowser.ReadyState < READYSTATE_INTERACTIVE
DO Application.ProcessMessages;
Doc := wbBrowser.Document;
Doc.Clear;
Doc.Write(HTMLCode);
doc.body.style.fontFamily:='Arial'; <------ won't work
Doc.DesignMode := 'On';
Doc.Close;
end;
You need to let the document be interactive again after you close the document.
e.g.:
procedure TForm1.SetHtmlCode(CONST HTMLCode: string);
VAR
Doc: Variant;
begin
if NOT Assigned(wbBrowser.Document)
then wbBrowser.Navigate('about:blank');
//WHILE wbBrowser.ReadyState < READYSTATE_INTERACTIVE // not really needed
//DO Application.ProcessMessages;
Doc := wbBrowser.Document;
//Doc.Clear; // not needed
Doc.Write(HTMLCode);
Doc.Close;
Doc.DesignMode := 'On';
WHILE wbBrowser.ReadyState < READYSTATE_INTERACTIVE
DO Application.ProcessMessages;
doc.body.style.fontFamily:='Arial';
ShowMessage(doc.body.outerHTML); // test it
end;
But I think the best way is to handle the OnDocumentComplete where you know you have a valid document/body, and set the style or what ever else needed.
I have usual code to show modal form. But sometimes happens strange bug captured on picture below. (about once per 10 attempt to show that form) It happens only with custom FireMonkey style "Diamond.style".
My code for setting style (in DPR file):
var
lib: THandle;
RS: TResourceStream;
begin
Application.Initialize;
lib := LoadLibrary('res.dll');
RS := TResourceStream.Create(lib, 'DIAMOND', RT_RCDATA);
try
TStyleManager.SetStyle(TStyleManager.LoadFromStream(RS));
finally
RS.Free;
end;
...
My code for showing form:
formProjectName := TformProjectName.Create(Self);
try
formProjectName.ShowModal;
...
finally
formProjectName.Free;
end;
I'm not sure if this is helpful.... but this is the code from my "OnChange" event of the TComboBox I use with the style names loaded:
var
resname :string;
style:TFMXObject;
begin
// set style to default...
if TOSVersion.Platform = pfAndroid then
resname := 'And';
if TOSVersion.Platform = pfWindows then
resname := 'Win';
if cbStyles.ItemIndex > 0 then
Begin
//(Add prefix to style name from TComboBox)
resname := resname + cbStyles.Selected.Text;
Style := TStyleStreaming.LoadFromResource(HInstance,resname, RT_RCDATA) ;
if style <> nil then
TStyleManager.SetStyle(style);
End;
// The below line causes hangs in some future version (just guessing:-) ) -- XE8 was OK.
//else TStyleManager.SetStyle(nil);
I load the TComboBox STyles like this typically...
CBStyles.Items.Clear;
CBStyles.Items.Add('Default');
if TOSVersion.Platform = pfAndroid then
begin
CBStyles.Items.Add('CoralCrystal');
CBStyles.Items.Add('CoralDark');
CBStyles.Items.Add('Diamond');
CBStyles.Items.Add('EmeraldCrystal');
CBStyles.Items.Add('EmeraldDark');
CBStyles.Items.Add('Jet');
CBStyles.Items.Add('Radiant');
CBStyles.Items.Add('Sterling');
CBStyles.Items.Add('Vapor');
end;
Maybe that will help...
I have dynamically created TValueListEditor VCL component on a TForm. The code is located in nested procedure of one of the main form's methods. I have set:
ValueListEditor.KeyOptions := [keyEdit, keyAdd, keyUnique];
It looks like this:
TMainForm.Method();
Method has a nested procedure that contains code that creates the components mentioned above.
Then, I have helper function:
function GetMenuListData(XMLNode: TXMLNode; const XNMLDoc: string = '') : string;
In this helper I use this code to load an XML file and then retrieve its nodes and insert them into ValueListEditor.
XMLDoc := TXMLDocument.Create(Self);
XMLDoc.ParseOptions := [poPreserveWhiteSpace];
try
XMLDoc.LoadFromFile(XNMLDoc);
try
Control := FindControl(FindWindow('TForm',PChar('(' + ExtractFileExt(Form1.Edit1.Text) + ')')));
if Control <> nil then
begin
TValuelistEditor(Control).Keys[TValuelistEditor(Control).RowCount-1] := XMLDoc.DocumentElement.NodeName;
if XMLDoc.DocumentElement.ChildNodes.First.AttributeNodes.Count > 0 then
TValuelistEditor(Control).Values[TValuelistEditor(Control).Keys[TValuelistEditor(Control).RowCount-1]] := String(XMLDoc.DocumentElement.Attributes['id'])
else
TValuelistEditor(Control).Values[TValuelistEditor(Control).Keys[TValuelistEditor(Control).RowCount-1]] := '<Empty>';
end else begin
MessageBeep(0);
FlashWindow(Application.Handle, True);
ShowMessagePos('...');
end;
finally
XMLDoc.Active := False; Result := 'Forced ' + Form1.RAWInputBtn.Caption + ' in ' + DateTimeToStr(Now);
end;
except
on E : EXMLDocError do
begin
Result := 'Forced ' + Form1.RAWInputBtn.Caption + ' in ' + DateTimeToStr(Now);
end;
end;
The problem is that I get access violations every time code goes into the line:
TValuelistEditor(Control).Keys[TValuelistEditor(Control).RowCount-1] := XMLDoc.DocumentElement.NodeName;
I have tried various typecasts, values, parameters .. nothing does the trick.
What is my mistake?
I'm using Delphi XE.
As Ken commented your problem is, instead of finding the value list editor, you are finding your form and then typecasting it to a value list editor, hence the AV.
First, you're passing 'TForm' as 'lpClassName' to FindWindow. Assuming 'TForm' is the class name of your form, it will of course find the form - not a child window on it. Second, you cannot use FindWindow to find a child window, see its documentation, it searches top-level windows.
If you had tested the return of FindControl, the code raising the AV would never run:
if (Control <> nil) and (Control is TValueListEditor) then
You can use FindWindowEx to search in child windows, if you don't know the handle of your form find it first as you've done already:
FormHandle := FindWindow('TForm',PChar('(' + ExtractFileExt(Form1.Edit1.Text) + ')'));
if FormHandle <> 0 then
begin
Control := FindControl(FindWindowEx(FormHandle, 0, 'TValueListEditor', nil));
or better yet, test the return of FindWindowEx first to avoid passing '0' to FindControl:
ValueListEditorHandle := FindWindowEx(FormHandle, 0, 'TValueListEditor', nil);
if Win32Check(ValueListEditorHandle <> 0) then
begin
Control := FindControl(ValueListEditorHandle);
if Assigned(Control) then
begin
...
If your dynamically created form is part of the same application, you don't need all the noise of the incorrect FindControl(FindWindow()). Just create your form, giving it a name, and making Application the owner:
MyForm := TMyForm.Create(Application);
MyForm.Name := 'MyDynamicForm';
When you want to get a new reference to it:
var
TheForm: TMyForm;
i: Integer;
begin
TheForm := nil;
for i := 0 to Screen.FormCount - 1 do
if Screen.Forms[i] is TMyForm then
// Could also use Screen.Forms[i].Caption
if Screen.Forms[i].Name = 'MyDynamicForm' then
TheForm := TMyForm(Screen.Forms[i]);
if Assigned(TheForm) then
TheForm.MethodThatLoadsXML(XMLFileName); // or whatever
end;
TheForm.MethodThatLoadsXML can now access the TValueListEditor directly:
procedure TMyForm.MethodThatLoadsXML(const XMLFileName: string);
begin
// Load xml as before, using XMLFileName
with TValueListEditor.Create(Self) do
begin
Options := [Whatever];
Parent := Self;
Left := SomeNumber;
Top := SomeNumber;
// Create items for value list from XML and other stuff
end;
end;