Mega Code Archive

 
Categories / Delphi / .NET
 

Delphi .NET DBWebImage SAD

Title: Delphi .NET - DBWebImage - SAD: Question: I need to show images from database in ASP.NET, but DBWebImage from Borland.Data.Web.dll disappointed me... Answer: greetings... Delphi for many years was the best, but now it is critical... anyone already needed to retrieve images from databases? many of us... but... in Delphi 2005 as Delphi 8 what we'll do with? Help? the help files doesn't help to much... all the examples are VB or C#... so sad... well... but the DBWebImage can help you... but only on a simple, very simple situation... the DBWebImage doesn't work: 1. if you use cookieless=true, because sessionID starts to be part of the url 2. if you try to pass a querystring value to this page. The image doesn't appear because the url is not the expected (just without parameters is expected, an absurd) 3. if you need to make a https site. Simply doesn't work because, again, the url is not the expected (http fixed is in the source code, not even a check is maded) 4. if you have a page with login, example, and you finally could show the image in the 1st or 2nd page, ok cool, but if you need to see another image from database in a sub-info page the DBWebImage uses the same temporarly filename, including the urlimage... so the first image acquired is the same image all along the application until you abandon the session (no comments, another absurd) In Delphi 8 I solve the problem... in terms... I have made modifications in the .cs in the dbwebcontrols source code... to pass through these problems... it was hard but I was able to recompile the Borland.Data.Web.dll with my own code and it works... I solved the 1st, 2nd and 3rd problems above, but the 4th still without solution... but works fine... Well... lately I'm testing Delphi 2005 and I'm very happy with newest Win32 resources and others stuff, but the same problems still remain... I have tried to use my modifications in the Borland.Data.Web.dell source again and the code is valid and complies, but occours a problem of PublicKeyToken that I don't know where I put this value, so is generated a null value, but a 91d62ebb5b0d1b1b is required... Well... I exposed the problems, and I like to propose a change... the Delphi users now have more competitors... not the VB users only, but PHP and Perl programmers... their applications are very useful and fast... so we need to face the problem... Would be fantastic an image solution with source codes that we could make in group as in this page: http://www.vbcity.com/forums/faq.asp?fid=37&cat=Database&#TID90816 just using an aspx as answer to the urlimage... but if you try to convert the code it stops at BinaryWrite... the compiler alerts "There is no overloaded version of 'BinaryWrite' that can be called with these arguments"... if anybody helps me on this BinaryWrite the code is praticly ready on this article... Ps.: If anyone wants to receive my modified Borland.Data.Web.dll source code to work on Delphi 8 or wants the own Borland.Data.Web.dll already recompiled send me a mail requesting it... but, sincerily, solving the BinaryWrite problems all is practily done... sorry for some terms missed in english... and thanks for attention... "...NOW, BELOW IS THE SOLUTION ONE DAY AFTER - WHAT BORLAND DOESN'T DO FOR US WE DO FOR HER..." Well friends, nothing better than a day of work... yesterday joining some infos and remembering the old times I mixed mi own mind and... finnaly solved the borland problem... Completely conscientious of the purpose of this delphi's community... I would like to share this solution... It works very easy... when you need an image from the database just set the imageurl as below... Usage: Image1.ImageUrl:='readimage.aspx?cd_field=cd_user&cd_value=' + TextBox1.Text + '&image_field=user_picture&table_name=users&checker=' + IntToStr(((StrToInt(TextBox1.Text) + 8) * 591) + 3008) + '&noimage=images/no_picture.jpg'; procedure TWebForm1.Page_Load(sender: System.Object; e: System.EventArgs); // create a simple aspx without any asp.net control Var CD_VALUE,CD_FIELD,IMAGE_FIELD,TABLE_NAME:String; CHECKER:LongInt; SQLConn:SQLConnection; SQLCmd:SQLCommand; SQLDtR:SQLDataReader; Buf:TBytes; FieldNum,BufSize,ImageFinder:Integer; begin CHECKER:=((StrToInt(Request.QueryString.Get('checker')) - 3008) Div 591) - 8; CD_VALUE:=Request.QueryString.Get('cd_value'); If CHECKER StrToInt(CD_VALUE) then Begin Response.Redirect(Request.QueryString.Get('noimage')); Exit; End; CD_FIELD:=Request.QueryString.Get('cd_field'); IMAGE_FIELD:=Request.QueryString.Get('image_field'); TABLE_NAME:=Request.QueryString.Get('table_name'); SQLConn:=SQLConnection.Create(ConfigurationSettings.AppSettings.Get('ConnectionString')); SQLCmd:=SQLCommand.Create( 'select ' + IMAGE_FIELD + ' from ' + TABLE_NAME + ' where ' + CD_FIELD + ' = ' + CD_VALUE + ' and ' + IMAGE_FIELD + ' IS NOT NULL' , SQLConn); ImageFinder:=0; SQLConn.Open; SQLDtR:=SQLCmd.ExecuteReader; While SQLDtR.Read do Begin Inc(ImageFinder); FieldNum:=SQLDtR.GetOrdinal(IMAGE_FIELD); BufSize:=SQLDtR.GetBytes(FieldNum, 0, Nil, 0, 0); SetLength(Buf, BufSize); SQLDtR.GetBytes(FieldNum, 0, Buf, 0, BufSize); Response.Clear; Response.BinaryWrite(Buf); Response.&End; End; SQLConn.Close; If ImageFinder = 0 then Response.Redirect(Request.QueryString.Get('noimage')); end; []'s Marcos Costa - Brasil