my goal is to make a funny application, that will play audio from chromium embedded component from youtube , while video will be shown from TWebBrowser component of another part of this series of movie (just for a joke)...
The problem is, i am unable to mute TWebBrowser in Delphi, however it worked in real Internet Explorer... Its enough to change the
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Play_Background_Sounds to "no" and Youtube in IE will not play audio (there is also no volume control icon on YT):
Youtube in IE
I tried to do this one in Delphi:
var rg:TRegistry ;
....
rg :=TRegistry.Create;
rg.RootKey :=HKEY_CURRENT_USER;
rg.OpenKey('\software\microsoft\internet explorer\main\',true);
rg.WriteString('Display Inline Images','no'); // for faster download - btw this one worked in TWebBrowser
rg.WriteString('Play_Background_Sounds','no'); // Not working in TWebBrowser , neither in TembeddedWB
not worked...
Also tried this one (flagged navigation):
const
DLCTL_DLIMAGES = $00000010;
DLCTL_VIDEOS = $00000020;
DLCTL_BGSOUNDS = $00000040;
DLCTL_NO_SCRIPTS = $00000080;
DLCTL_NO_JAVA = $00000100;
DLCTL_NO_RUNACTIVEXCTLS = $00000200;
DLCTL_NO_DLACTIVEXCTLS = $00000400;
DLCTL_DOWNLOADONLY = $00000800;
DLCTL_NO_FRAMEDOWNLOAD = $00001000;
DLCTL_RESYNCHRONIZE = $00002000;
DLCTL_PRAGMA_NO_CACHE = $00004000;
DLCTL_FORCEOFFLINE = $10000000;
DLCTL_NO_CLIENTPULL = $20000000;
DLCTL_SILENT = $40000000;
DLCTL_OFFLINEIFNOTCONNECTED = $80000000;
and then
var
WebPage: Integer;
flags: OleVariant;
WebPage := 'https://youtube.com/ ...';
Flags := DLCTL_BGSOUNDS +
DLCTL_PRAGMA_NO_CACHE +
0 ;
iexplorer1.navigate(webpage,flags);
no success again...
What am I doing wrong?
Every help will be appreciated..
PS: Sorry for my english
Related
Please help me to translate the code. I don't know C++ well, but I know Delphi syntax well. I want to translate code from MSDN:
Step 6. Add Support for COM.
static WCHAR g_wszName[] = L"My RLE Encoder";
CFactoryTemplate g_Templates[] =
{
{
g_wszName,
&CLSID_RLEFilter,
CRleFilter::CreateInstance,
NULL,
NULL
}
};
and
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]);
I realized that the first line is a variable. But when translated, it does not work. Error:
This is a string and you defined it as WCHAR.
Next comes the description of the structure, but I do not know such a form.
The last line is also a variable, but it has a / and two values.
In general, I kind of understood the meaning, but do not understand how to write it.
The code roughly translates to Delphi as follows:
const
g_wszName: PWideChar = 'My RLE Encoder';
var
g_Templates: array[0..0] of CFactoryTemplate;
...
g_Templates[0].m_Name := g_wszName;
g_Templates[0].m_ClsID := #CLSID_RLEFilter;
g_Templates[0].m_lpfnNew := #CRleFilter.CreateInstance;
g_Templates[0].m_lpfnInit := nil;
g_Templates[0].m_pAMovieSetup_Filter := nil;
and
var
g_cTemplates: Integer;
...
//g_cTemplates := SizeOf(g_Templates) div SizeOf(g_Templates[0]);
g_cTemplates := Length(g_Templates);
I am using Delphi XE6 and LockBox 3.4.3 to run the code actEncryptStringExecute. This code was posted as an answer to the question 'How to use AES-256 encryption in lockbox 3 using delphi'.
The error I get is TSimpleCodec.Begin_EncryptMemory - Wrong mode.
There is another question 'TSimpleCodec.Begin_EncryptMemory - Wrong mode' where the answer is "You don't need to do this if you are setting up the codec with design-time values. It's much easier to do at design-time. Just set the published properties as required".
TCodec properties are :-
AdvancedOptions2 = []
AsymetricKeySizeInBits = 1024
ChainMode = ECB (with block padding)
Cipher = Base64
CryptoLibrary = CryptographicLibrary1
Encoding = (TEncoding)
TCryptographicLibrary properties are :-
CustomCipher = (TCustomStreamCipher)
Name = CryptographicLibrary1
ParentLibrary =
The code is :-
var
base64CipherText : String;
PlainTextStr : String;
ReconstructedPlainTextStr : String;
procedure TForm1.btnEncryptClick(Sender: TObject);
begin
PlainTextStr := edtPlainText.Text;
Codec1.EncryptString(PlainTextStr, base64CipherText, TEncoding.Unicode);
lblEncrypted.Caption := base64CipherText;
Codec1.DecryptString(ReconstructedPlainTextStr, base64CipherText, TEncoding.Unicode);
lblReconstructed.Caption := base64CipherText;
end;
What do I need change at design time to get this most simple example to work?
This code gives me error
ex.Cells [3, 2]. HorizontalAlignment: = xlright;
ex.Cells [row, 1]. NumberFormat: = 'dd / mm / yy, #';
how can I fix this?
thanks
Based on your other questions, you're using late binding (using a Variant) instead of early binding (using the VCL TExcelApplication and other components). This means that the specific types like xlRight are not defined, because you haven't used the type library import that provides them. You'll have to define them yourself:
var
...
NewAlign: OleVariant;
const
xlBottom = $FFFFEFF5;
xlLeft = $FFFFEFDD;
xlRight = $FFFFEFC8;
xlTop = $FFFFEFC0;
xlHAlignCenter = $FFFFEFF4;
xlHAlignCenterAcrossSelection = $00000007;
xlHAlignDistributed = $FFFFEFEB;
xlHAlignFill = $00000005;
xlHAlignGeneral = $00000001;
xlHAlignJustify = $FFFFEFDE;
xlHAlignLeft = $FFFFEFDD;
xlHAlignRight = $FFFFEFC8;
begin
// XLApp is the instance of Excel you set up from your previous
// questions
XLApp.Workbooks[1].Worksheets[1].Range['C1:C5'].NumberFormat := 'dd/mm/yy';
NewAlign := xlHAlignRight;
XLApp.Workbooks[1].Worksheets[1].Range['C1:C5'].HorizontalAlignment := NewAlign;
end;
Assigning dd/mm/yy # makes no sense, because it's either a date format dd/mm/yy or text #, but not both.
I'm using this code to acquire the scanned image from WIA:
const
wiaFormatJPEG = '{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}';
wiaFormatPNG = '{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}';
var
CommonDialog: ICommonDialog;
AImage: IImageFile;
i: Integer;
begin
CommonDialog := CreateOleObject('WIA.CommonDialog') as ICommonDialog;
for i := 1 to Scanner.Properties.Count do
begin
if (Scanner.Properties[i].Name = 'Horizontal Resolution') or
(Scanner.Properties[i].Name = 'Vertical Resolution') then
Scanner.Properties[i].Set_Value(72)
else if Scanner.Properties[i].Name = 'Horizontal Extent' then
Scanner.Properties[i].Set_Value(Round(8.27 * 72))
else if Scanner.Properties[i].Name = 'Vertical Extent' then
Scanner.Properties[i].Set_Value(Round(11.00 * 72));
end;
AImage := IUnknown(CommonDialog.ShowTransfer(Scanner, wiaFormatPNG, True)) as IImageFile;
//Save the image
AImage.SaveFile('D:\1.' + AImage.FileExtension);
imgImage.Picture.LoadFromFile('D:\1.' + AImage.FileExtension);
DeleteFile('D:\1.' + AImage.FileExtension);
end;
Scanner is initialized using this code:
Scanner := DevMgr.DeviceInfos[Integer(cbWIASource.Items.Objects[cbWIASource.ItemIndex])].Connect.Items[1];
And DevMgr and cbWIASource are initialized using this code:
DevMgr := CreateOleObject('WIA.DeviceManager') as IDeviceManager;
for i := 1 to DevMgr.DeviceInfos.Count do
for j := 1 to DevMgr.DeviceInfos[i].Properties.Count do
if DevMgr.DeviceInfos[i].Properties[j].Name = 'Name' then
begin
cbWIASource.Items.AddObject(DevMgr.DeviceInfos[i].Properties[j].Get_Value, TObject(i));
Break;
end;
I was wondering if there is a way to copy the scanned document without first saving it to the disk. I read on MSDN that I can access ARGBData member of ImageFile to access pixel data, but is there a simple way to copy the entire image from FileData to TBitmap? For instance, can I use a TMemoryStream?
Just as an update, I found this example on MSDN. I know nothing about VB, but I guess the Picture object is a wrapper around HBITMAP. So, is it logical to conclude that the ImageFile.Picture property is what I need?
IImageFile has a property FileData with provides access to the binary image data, via IVector.BinaryData
I want to create light object data-package to pass between client and server applications.
It is a so simple task, that I can control with only 1 byte, so
each bit in a byte will have a different meaning,
Using only the bit
0 = False
1 = True
Itens I need now:
1 - Loaded from database
2 - Persisted
3 - Changed
4 - Marked to Delete
5 -
6 -
7 - Null Value
8 - Read Only
1) How do I use bit operators in Delphi to check each bit value?
2) How do I set the bit Values?
Solution
After all help, Ill use the next Set
TStateType = (
stLoaded = 0, // loaded from persistance
stNative = 2, // value loaded and converted to native type
stPersisted = 3, // saved
stChanged = 4, // object or member changed
stToDelete = 5, // marked to delete
stReadOnly = 6, // read only object, will not allow changes
stNull = 7 // value is null
);
TState = Set of TStateType;
And for stream -> persistance, this will be the record to be used:
TDataPackage = record
Data: TBytes;
TypeInfo: TMetaInfo;
State: Byte;
Instance: TBuffer;
end;
Thank you guys, for all the answers and comments.
I'd really use a set for this. However, I see you really want a byte. Use sets everywhere then typecast to a byte in the end.
This solution will require much less typing, has support for standard delphi operators and really carries no performance penalty as Barry Kelly has pointed out.
procedure Test;
type
TSetValues = (
TSetValue1 = 0,
TSetValue2 = 1,
TSetValue4 = 2,
TSetValue8 = 3,
TSetValue16 = 4,
TSetValue32 = 5,
TSetValue64 = 6,
TSetValue128 = 7
);
TMySet = set of TSetValues;
var
myValue: byte;
mySet: TMySet;
begin
mySet := [TSetValue2, TSetValue16, TSetValue128];
myValue := byte(mySet);
ShowMessage(IntToStr(myValue)); // <-- shows 146
end;
I would use a set for this:
type
TMyDatum = (mdLoaded, mdPersisted, mdChanged, mdMarkedToDelete, ...);
TMyData = set of TMyDatum;
var
Foo: TMyData;
begin
Foo := [mdLoaded, mdChanged];
if (mdPersisted in Foo) then ...
These are implemented as integers, so you can pass them easily. And I find the code much, much more readable than bitwise operators.
This page describes Delphi operators, including bitwise operators.
It sounds like you need to use the and operator. For example:
const
LOADED_FROM_DATABASE = 1;
PERSISTED = 2;
CHANGED = 4;
// etc...
//...
if (bitFlags and LOADED_FROM_DATABASE) <> 0 then
begin
// handle LOADED FROM DATABASE
end;
if (bitFlags and PERSISTED) <> 0 then
begin
// handle PERSISTED
end;
// etc...
In order to set the flags, you can use OR:
bitFlags := LOADED_FROM_DATABASE or PERSISTED or CHANGED;