Display Bitmap Image from Access to Delphi 7 - delphi

Regards for all Delphi Guru :)
I have table in Access 2010, one of the column type is OLE Object named "ProductImage"
I use that column to save Bitmap Image.
The problems is, How can I display that image using DBImage or TImage in Delphi 7?
I've tried this
procedure TF_Search2.DBGrid1CellClick(Column: TColumn);
begin
Image7.Picture.Assign(DataModule1.T_Products.FieldByName('ProductImage').LoadFromFile('c:\test.jpg'));
end;
It's error : need parameter in this part 'LoadFromFile('c:\test.jpg')'
I tried also using "TBlobField", but I got error : undeclared identifier TBlobField
I read that it should in unit and uses. I don't understand what's that mean.
Should I add something on installation folder or what?
Any helps would be appreciated.
Thank You

The field also contains an OLE Header. I ancient times I skipped this (I think the first 79 bytes) but I cannot find the code anymore. However, the internet has solutions as always. Imho this one is better than my 'skip' solution.
Here is one of them:How to read and write images from/to an access DB (page 4)
EDIT: I just saw that your problem is your syntax.
procedure TF_Search2.DBGrid1CellClick(Column: TColumn);
begin
Image7.Picture.Assign(DataModule1.T_Products.FieldByName('ProductImage').LoadFromFile('c:\test.jpg'));
end;
This is not valid delphi syntax and quite confusing. The Picture.Assign method expects a picture object. So what you first would want to do is to get the picture out of the access-DB.
You want to read the image data from an access db and display it in an image component?
Follow the steps in the link.
EDIT: I did find some very old code which I modified (and cannot test):
aBitmapStream := TMemoryStream.Create;
tblDrawing_BitmapColumnBLobField.SaveToStream (aBitmapStream);
// This hack enables Access BMP-Blobs to be imported
aBitmapStream.Seek (78,soFromBeginning);
myBitmap := TBitmap.Create;
myBitmap.LoadFromStream (aBitmapStream);
Image7.Picture.Assign (myBitmap);
myBitmap.Free;
aBitmapStream.Free;

Related

Changing background image in TeeChart Delphi XE8 at run-time

I would like to use the gallery pictures (Metal, Wood, Stone, Clouds, etc.) which are available at design time under Chart/Panel/Image/Gallery.
If I set it at design time, I can easily disable it at run time with:
g.backImage := nil;
But if I want to set it to a particular value, e.g. with
g.backImage := 'metal';
I get an 'Incompatible types' error, because the compiler requires a TBackImage value. I do not have the source codes, and I cannot find the appropriate values on several Google searches.
Thinking that it could be just an enum, I tried typecasting it to one:
g.backImage := TBackImage(1);
But it generates an exception. I also tried to "guess" the names, like tbiMetal, tbMetal, tMetal, and so on, to no avail...
What are those values?! Thank you
TBackImage is a class whose methods you must call.
Chart.BackImage.LoadFromFile('full/path/to/imagefile');
Those are real texture images embedded in TBrushDialog, they can be used/accessed like this:
uses TeeBrushDlg;
procedure TForm1.FormCreate(Sender: TObject);
var BrushDialog: TBrushDialog;
begin
BrushDialog:=TBrushDialog.Create(Self);
Chart1.BackImage.Graphic:=BrushDialog.ImageCarbon.Picture.Graphic;
end;

Delphi Firemonkey - loading style at runtime

I have loaded a couple of the sample styles from ......\RAD Studio\9.0\Styles as resources into my project and am 'simply' trying to load one of them at runtime.
I'm using the following code to try and do this:
var
vResourceStream : TResourceStream;
begin
vResourceStream := TResourceStream.Create( HInstance, 'DARKSTYLE', RT_RCDATA );
try
StyleBook1.LoadFromStream( vResourceStream );
finally
vResourceStream.Free;
end;
It compiles ok but when I run it I get a bunch of errors, the first being 'Property Align does not exist' then 'Error reading TStyleBook.Align: Property Align does not exist' and it seems to do this for a bunch more atributes, Height etc.
Can someone give me some pointers as to how to solve it please?
Not that I know a bit about FMX, but AFAIU the .style files are resource definition files. Instead of reading the stylebook object from the stream, you should read its resource:
StyleBook1.Resource.LoadFromStream( vResourceStream );
For reference, there are LoadFromStream and LoadFromFile methods at TStyleBook, but there is also TStyleStreaming class with an extra LoadFromResource utility method (apart from its own LoadFromStream and LoadFromFile). Probably they should add a LoadFromStream to TStyleBook class too (guess it would call into the respective TStyleStreaming one)

How to set THTTPRio.Converter.Options to soLiteralParams in OnBeforeExecuteEvent

This refer to the post Delphi SOAP Envelope and WCF.
Could someone please post a sample code which can show me how to set soLiteralParams in THTTPRio.Converter.Options in Delphi 7. I have the following code currently.
I have drag-dropped a HTTPRIO component into the document which has created a line HTTPRIO1: THTTPRIO at the beginning of the code. I basically want to understand how I set soLiteralParams in the above component. Following is the code I am trying to execute which is giving me error.
procedure TForm1.CleanUpSOAP(const MethodName: String; var SOAPRequest: WideString);
var RIO: THTTPRIO;
begin
//The following line is giving error
// RIO.Converter.options := [soLiteralParams];
end;
In the above code I have declared a variable RIO of the type THTTPRIO, which I am not sure is correct.
Just guessing, as you provide very little information in your question.
Use the variable assigned to the component you dropped on your form. Don't declare a new local one (which you never created anyway). To set the Converter.Options in code, you'll need to add OPToSOAPDomConv to your uses clause.
implementation
uses
OPToSOAPDomConv;
// BTW, this name might not be a good one if it's the
// OnBeforeExecute event handler as that isn't
// clear from the name.
procedure TForm1.CleanUpSOAP(const MethodName: String; var SOAPRequest: WideString);
begin
// Note this clears any previous options!
HTTPRIO1.Converter.Options := [soLiteralParams];
// If you want to keep the previous options instead of replacing them
// HTTPRIO1.Converter1.Options := HTTPRIO1.Converter1.Options + [soLiteralParams];
end;
If you've dropped the component on the form, I'm not sure why you're not handling this in the Object Inspector instead, however.
If this doesn't solve the problem, edit your question and provide the exact error message you're receiving, including any memory addresses in the case of an exception being raised.
I have cracked this. The issue was that I didn't refer to OPconvert.pas file, which contained the TSOAPConvertOption enumeration. I don't know whether copying this file into the same folder as my project files and referring to this in the "uses" section is the right way, but it worked fine.

saving delphi routines and memory

This question is about being able to save routines, and being able to select them from a list…. When you select one it knows what to link where etc. Just for understanding. not the actual program
Say I want to create a routine in a Delphi form. And I want to create several different ones. They wont be exactly the same but some might be similar. I want to know how you can save things in Delphi and when you close or terminate the application they will remain remembered when you reopen it. I have no idea where to start and how to work this. Any help would be great. Just a hint or a direction, maybe a website with more info or even examples. I’m going to try to give a simpler description below about how it would look on the form…. Just for the idea and I think if I understand this then it would be enough, or a good start at least.
The form will contain a list box a save button and 4 different edit boxes. Lets say I type in edit1;1 and edit2;2 and edit3;3 and edit4;4. Then click the save button and it remembers these 4 value to each edit box and lets say saves in under the value in the list box of ≔edit1.text + ‘to’ + edit4.text. Hope it makes sense so far and then I type in the edit boxes everything the wrong way around. edit1;4 and edit2;3 and edit3;2 and edit4;1. And click save button and it does that again (≔edit1.text + ‘to’ + edit4.text) into the list box. Then I want to close the application. Open it again and still have this in there and still be able to add more of these odd samples….
Can anyone help me?
Edit question, might make it more clear....
I'm going to place the following elements on the form: 2 listboxes(with each 3 lines, in the first listbox: wood, plastic and glass. in the second listbox: tree,cup,window.)
Now I want to link the correct ones, they are in order here, but what is they were not. In a table or in a memory of the application which is not visible on the form I want to link them.
Then if i were to put two edit boxes on the form as wel and I type in the first one wood or tree, it places the other one in the other edit box. So in a way I suppose you are creating a table which knows which one correcsponds with which but also looksup up when you type in edit box. hope that makes sense
From what you wrote I assume that you already know how to add the values to remember to your list box, so I won't deal with this part here. Starting with this answer, you should already have a clue to what to look at in the delphi help files. Please be aware that I didn't test the example, so there may be typos in it.
To store data in the computers registry, delphi provides you with the unit Registry, which contains a class TRegistry.
TRegistry has all the methods needed to retrieve and store values. Following is a short example without any practical use, just to give you the picture. Please be aware that, like mentioned in the comments, there's plenty of room left for you to optimise it. It would, for example, be better to create the TRegistry object only once and then repeatedly call the methods. And - while this plain old delphi unit I wrote is syntactically valid - you might be better off using a more object-oriented approach, like deriving a new class from TRegistry. Please do also check the documentation for the return values of the methods, as some (like OpenKey) simply return false when they are unable to fulfill your request while others (like ReadString) can throw an execption.
unit Unit1;
interface
uses TRegistry, Windows;
procedure saveStringToRegistry(name : String; value : String);
function readIntegerFromRegistry(name : String) : Integer;
implementation
procedure saveStringToRegistry(name : String; value : String);
var r : TRegistry;
begin
r := TRegistry.Create;
try
r.RootKey := HKEY_CURRENT_USER; // Defined in unit Windows, as well as HKEY_LOCAL_MACHINE and others.
r.OpenKey('Software\Manufacturer Name\Produkt Name\Other\Folders',true); // TRUE allows to create the key if it doesn't already exist
r.WriteString(name,value); //Store the contents of variable 'value' in the entry specified by 'name'
r.CloseKey;
finally
r.Free;
end;
end;
function readIntegerFromRegistry(name : String) : Integer;
var r : TRegistry;
begin
r := TRegistry.Create;
try
r.RootKey := HKEY_LOCAL_MACHINE; // Defined in unit Windows
r.OpenKey('Software\Manufacturer Name\Produkt Name\Other\Folders',false); // FALSE: do not create the key, fail if it doesn't already exist
result := r.ReadInteger(name);
r.CloseKey;
finally
r.Free;
end;
end;
end.
OK, now you could use a for loop in your application to process all the items of your list box and save it to the registry using the procedure above, like this:
for i := 0 to ListBox1.Count -1 do
saveStringToRegistry('Entry' + IntToStr(i),ListBox1.Items[i];
Then, you would probably save the number of items you have (of course you would have to define the procedure saveIntegerToRegistry):
saveIntegerToRegistry('NumberOfEntries',ListBox1.Count);
When you need to reload the data, you could do:
ListBox1.Clear;
for i := 0 to readIntegerFromRegistry('NumberOfEntries') -1 do
ListBox1.Items.Add(readStringFromRegistry('Entry' + IntToStr(i));
OK, it's a very basic example, but should give you pointer in the right direction. It could of course need some exception handling (imagine the user accidently deleted Entry42 from the registry, but NumberOfEntries still says there are 55 entries).

How do I get the sha-256 hash of a section which contains code in a Portable Executable file, in Delphi?

I would like to get the sha-256 hash for a section which contains code(.text, CODE) in a Portable Executable file, in Delphi.
So far, I've tried to get the start and end address of the section to which the AddressOfEntryPoint points to, but if I load the same file several times, I get different start and end addresses.
Can anyone please help me?
This is the code:
procedure TForm1.Button1Click(Sender: TObject);
var x:TJCLPEImage;
aoep,cs,ce: cardinal;
pise: Pimagesectionheader;
nos : integer;
i : integer;
begin
x := TJCLPEImage.Create();
x.FileName:=edit1.Text;
aoep := x.OptionalHeader32.AddressOfEntryPoint;
pise := Pointer(PByte(#(x.LoadedImage.FileHeader.OptionalHeader)) + x.LoadedImage.FileHeader.FileHeader.SizeOfOptionalHeader);
for i:=0 to x.ImageSectionCount-1 do
begin
if (pise.VirtualAddress <= aoep) and (aoep < (pise.VirtualAddress + pise.Misc.VirtualSize)) then
break;
end;
inc(pise);
cs := DWORD(x.LoadedImage.MappedAddress) + DWORD(pise.PointerToRawData);
ce := cs + pise.Misc.VirtualSize;
Label1.caption:='Code start: '+Inttostr(cs);
Label2.caption:='Code end: '+inttostr(ce);
end;
Thank you.
I cant comment to your question yet, so i am trying to reply here, but not sure if i am thinking right about what you are asking.
Seems you want a way to assure no one changed your file after it loaded in memory.
That's why you want a sha-256 hash of that section, and probably you need to get that section and then hash it.
I never used JCL classes to do that. But found this unit that maybe help for you. It allow you to edit PE files. Was written in 2007, so maybe you will need upgrade some code. But i am most sure you will find the bases to what you want.
http://www.coderprofile.com/networks/source-codes/71/portable-executable-file-unit
I could not test it at all. But till what i tested, the start address did not changed here..
To get the Sha-256, will find many VCL components (or at least ActiveX) to do that. I could advise you to use LIBEAY32.DLL, but that would probably add one more dll to your application. Unless you already use it.
Hope that help in anyway.

Resources