Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » HowTo bind StaticImage to SQL
HowTo bind StaticImage to SQL [message #43611] Sat, 13 September 2014 06:32 Go to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Can someone show me how to bind a SQL3 field to a StaticImage control?

I am able to bind the other fields to controls. Problem is with StaticImage fed with filename

This is what I have right now
TABLE_ (RUN)
	INT_		(REFNO)	PRIMARY_KEY AUTO_INCREMENT
	DATE_ 		(TESTDATE)
	INT_		(MODE)
	INT_		(RADLEVEL)
	INT_		(RADTIME)
	INT_		(RADSP)
	INT_		(COILS)
	STRING_		(IMGFILE	,256)
END_TABLE



and this is how I bind them. gridHist is a SqlArray, siImage is a StaticImage
content in SQL[IMGFILE] is a filename on disk.
	History.gridHist.Reset();
	SQL * Select(SqlAll()).From(RUN);
	History.gridHist.SetTable(RUN);
	History.gridHist.AddColumn(TESTDATE,  "TestDate");
	History.gridHist.AddColumn(IMGFILE, "Image File");
	History.gridHist.SetOrderBy(TESTDATE);
	History.gridHist.AddCtrl(RADLEVEL, 	History.stRadLevel);
	History.gridHist.AddCtrl(RADSP, 	History.stAlarmSP);
	History.gridHist.AddCtrl(RADTIME, 	History.stMonTime);
	History.gridHist.AddCtrl(MODE, 		History.stMode);
//	History.gridHist.AddCtrl(IMGFILE, 	History.siImage);   this line does not work
//	History.gridHist.WhenCursor = THISBACK(ViewEvent);          If I use this, I do not get the image corresponding to cursor selection. It is always the first row image.
	History.gridHist.Query();


Is there a way to do what I'm trying?
Re: HowTo bind StaticImage to SQL [message #43615 is a reply to message #43611] Sat, 13 September 2014 22:26 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello Jerson,

To put images in SQL I use this:
//========================================
//          IMAGES
// ========================================
TABLE_(IMAGES)
	INT_	(IMG_ID) PRIMARY_KEY AUTO_INCREMENT
	LONGRAW_(IMG_DATA)
END_TABLE


And to update image in sql:
	sql * SqlUpdate(IMAGES)(IMG_DATA, SqlBinary( JPGEncoder().SaveString(img) ) ).Where(IMG_ID == resId);


In fact the image is stored as a string (I don't remember why: it's been 3 years since I wrote this code, maybe because I export it in XML afterwards

Hope this helps
Re: HowTo bind StaticImage to SQL [message #43616 is a reply to message #43615] Sun, 14 September 2014 05:16 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hello Didier

Thanks for your help. I am trying to figure out a way to feed the filename from a SQL.Field to the staticimage control. The Database holds just the file name. All other parameters are correctly tied to their respective controls. The only one that does not work is StaticImage.Set(String _filename). I suppose it is doing that since it is not an editable class.

If that is not possible, would you know how to get the field value from the cursor position on the sqlarray control? I could then use the whenevent to update the static control. Is that possible at all?

regards
Re: HowTo bind StaticImage to SQL [message #43618 is a reply to message #43616] Mon, 15 September 2014 07:58 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

I finally found a way to get my image to the control. Maybe it is crude, maybe there is a better way to do it, I don't know. This works for me.

I created a new static image which has the SetData method needed by SqlArray functions.
// subclass StaticImage widget to capture the mouse clicks
class JFStaticImage : public StaticImage {
typedef	JFStaticImage CLASSNAME;

public:
	virtual void LeftDown(Point p, dword keyflags);

//	Callback1 	WhenAction;

	JFStaticImage(){};
	void	SetData(const Value& data)	{String fn=data;  Set(fn);}
};


Now, I can simply do this and it works
	History.gridHist.AddCtrl(IMGFILE, 	History.siImage);


Anyone has other ideas, please let me know. I am eager to learn.

Regards
Jerson
Re: HowTo bind StaticImage to SQL [message #43629 is a reply to message #43618] Tue, 16 September 2014 09:46 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello Jerson

Using Set(), do you want to store the file name or the Image?


Best regards
Iñaki
Re: HowTo bind StaticImage to SQL [message #43630 is a reply to message #43629] Tue, 16 September 2014 10:25 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hi Koldo

I am just saving a filename to the table. This filename is fed to StaticImage by binding it with SQL.AddCtrl method.

I realized the StaticImage has no SetData method which is what the Sql.AddCtrl uses to update the image. So, I encapsulated the StaticImage to provide this method.

Regards
Jerson
Re: HowTo bind StaticImage to SQL [message #43638 is a reply to message #43630] Wed, 17 September 2014 08:09 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello Jerson

A problem about this is that it is not clear the behavior of SetData(). Should it save the image file name, or the image itself?

In fact, there are already two versions of StaticImage::Set(), one for file name and other for Image data.

A possible solution would be to add a method to indicate what will be the Set() behavior.


Best regards
Iñaki
Re: HowTo bind StaticImage to SQL [message #43640 is a reply to message #43638] Wed, 17 September 2014 12:32 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hi Koldo

I realized that. Set has two overloads - Image and String.

Since StaticImage does not expose a SetData method, the SqlArray could not update the control when fed with a filename from the table.

Therefore, I created the SetData method and tied it down to Set(String& filename) and when SetData is fed with a string parameter, it works correctly now.

Regards
Jerson
Re: HowTo bind StaticImage to SQL [message #43655 is a reply to message #43640] Thu, 18 September 2014 08:40 Go to previous message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Quote:
A possible solution would be to add a method to indicate what will be the Set() behavior.


???


Best regards
Iñaki
Previous Topic: StaticImage cannot show BMP file
Next Topic: >Port 9(say port 10)
Goto Forum:
  


Current Time: Fri Apr 19 01:19:50 CEST 2024

Total time taken to generate the page: 0.04275 seconds