1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
unit MySQLResultSetFieldViewer;
interface
uses
gnugettext, Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, TntForms, Forms,
Dialogs, ExtCtrls, TntExtCtrls, ComCtrls, TntComCtrls,
AuxFuncs, myx_public_interface, StdCtrls, TntStdCtrls,
PNGImage, Jpeg, UniCodeEditor, TntSysUtils, MySQLResultSet;
type
TViewerMode = (ViewerModeView, ViewerModeEdit);
TViewerContentType = (
ViewerContentTypeNone,
ViewerContentTypeText,
ViewerContentTypeImage,
ViewerContentTypeBinary
);
TMySQLResultSetFieldViewerForm = class(TTntForm)
PageControl: TTntPageControl;
TextSheet: TTntTabSheet;
ImageSheet: TTntTabSheet;
TextMemo: TTntMemo;
BinarySheet: TTntTabSheet;
HexUniCodeEd: TUniCodeEdit;
PlainTextUniCodeEdit: TUniCodeEdit;
TntSplitter1: TTntSplitter;
ImageScrollBox: TTntScrollBox;
FieldImage: TTntImage;
TextSheetBtnPnl: TTntPanel;
OKBtn: TTntButton;
CancelBtn: TTntButton;
ImageSheetBtnPnl: TTntPanel;
Ok2Btn: TTntButton;
Cancel2Btn: TTntButton;
TntPanel1: TTntPanel;
OK3Btn: TTntButton;
Cancel3Btn: TTntButton;
ImageFormatTitleLbl: TTntLabel;
TntBevel1: TTntBevel;
ImageSizeTitleLbl: TTntLabel;
ImageFormatLbl: TTntLabel;
ImageSizeLbl: TTntLabel;
BinarySizeTitelLbl: TTntLabel;
BinarySizeLbl: TTntLabel;
procedure PlainTextUniCodeEditScroll(Sender: TCustomUnicodeEdit; DeltaX, DeltaY: Integer);
procedure HexUniCodeEdScroll(Sender: TCustomUnicodeEdit; DeltaX, DeltaY: Integer);
constructor Create(AOwner: TComponent; Mode: TViewerMode); reintroduce;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FMode: TViewerMode;
FContentType: TViewerContentType;
FChanging: Boolean;
public
procedure SetContent(RSValue: TRSFieldValue);
property ContentType: TViewerContentType read FContentType;
end;
//----------------------------------------------------------------------------------------------------------------------
implementation
uses
ApplicationDataModule, Options;
{$R *.dfm}
//----------------------------------------------------------------------------------------------------------------------
constructor TMySQLResultSetFieldViewerForm.Create(AOwner: TComponent; Mode: TViewerMode);
begin
inherited Create(AOwner);
FMode := Mode;
if Mode = ViewerModeView then
begin
CancelBtn.Visible:=False;
OKBtn.Left:=CancelBtn.Left;
Cancel2Btn.Visible:=False;
OK2Btn.Left:=Cancel2Btn.Left;
Cancel3Btn.Visible:=False;
OK3Btn.Left:=Cancel3Btn.Left;
TextMemo.ReadOnly := True;
end;
FContentType:=ViewerContentTypeNone;
FieldImage.Left:=0;
FieldImage.Top:=0;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMySQLResultSetFieldViewerForm.FormCreate(Sender: TObject);
begin
InitForm(Self);
ApplicationDM.Options.RestoreWindowPos(Self);
Font.Name := MYXCommonOptions.DataFontName;
PageControl.ActivePageIndex := 0;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMySQLResultSetFieldViewerForm.FormDestroy(Sender: TObject);
begin
ApplicationDM.Options.AddWindowPos(self);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMySQLResultSetFieldViewerForm.SetContent(RSValue: TRSFieldValue);
var
ImgFormat: MYX_IMAGE_FORMAT;
MemStream: TMemoryStream;
PNGImage: TPNGObject;
JPEGImage: TJPEGImage;
Data: String;
Buffer: PChar;
i, j: Integer;
s, s1: WideString;
c: Char;
begin
ImageSheet.TabVisible := False;
TextSheet.TabVisible := False;
BinarySizeLbl.Caption := FormatFloat('###,###,###', RSValue.Length) + ' ' + _('Bytes');
if(RSValue.BinaryData)then
begin
ImgFormat := myx_guess_image_format(RSValue.Value, RSValue.Length);
if (ImgFormat <> MYX_IMG_UNKNOWN) and (ImgFormat <> MYX_IMG_GIF) then
begin
ImageSheet.TabVisible := True;
PageControl.ActivePage := ImageSheet;
FContentType:=ViewerContentTypeImage;
PageControl.ActivePage:=ImageSheet;
ImageSizeLbl.Caption := FormatFloat('###,###,###', RSValue.Length)+' '+_('Byte');
MemStream := TMemoryStream.Create;
try
SetString(Data, PChar(RSValue.Value), RSValue.Length);
if Data <> '' then
begin
MemStream.WriteBuffer(PChar(Data)^, RSValue.Length);
MemStream.Position := 0;
end;
case ImgFormat of
MYX_IMG_PNG:
begin
ImageFormatLbl.Caption := _('PNG');
PNGImage := TPNGObject.Create;
try
try
PNGImage.LoadFromStream(MemStream);
FieldImage.Picture.Assign(PNGImage);
except
ShowModalDialog(_('PNG image corrupted.'), _('The BLOB field contains a corrupted image file.'),
myx_mtError, 'Ok');
FieldImage.Picture.Bitmap.FreeImage;
end;
finally
PNGImage.Free;
end;
end;
MYX_IMG_JPEG:
begin
ImageFormatLbl.Caption := _('JPEG');
JPEGImage := TJPEGImage.Create;
try
try
JPEGImage.LoadFromStream(MemStream);
FieldImage.Picture.Assign(JPEGImage);
except
ShowModalDialog(_('JPG image corrupted.'), _('The BLOB field contains a corrupted image file.'),
myx_mtError, 'Ok');
FieldImage.Picture.Bitmap.FreeImage;
end;
finally
JPEGImage.Free;
end;
end;
MYX_IMG_BMP:
begin
ImageFormatLbl.Caption := _('BMP');
try
FieldImage.Picture.Bitmap.LoadFromStream(MemStream);
except
ShowModalDialog(_('JPG image corrupted.'), _('The BLOB field contains a corrupted image file.'),
myx_mtError, 'Ok');
FieldImage.Picture.Bitmap.FreeImage;
end;
end;
end;
FieldImage.Invalidate;
finally
MemStream.Free;
end;
FieldImage.Invalidate;
end;
end
else
begin
TextSheet.TabVisible := True;
PageControl.ActivePage := TextSheet;
FContentType:=ViewerContentTypeText;
if not RSValue.IsNull then
TextMemo.Text := TntAdjustLineBreaks(UTF8Decode(RSValue.Value))
else
TextMemo.Text := '';
ImageSheet.TabVisible := False;
end;
GetMem(Buffer, RSValue.Length*2+1);
try
BinToHex(PChar(RSValue.Value), Buffer, RSValue.Length);
j:=0;
i:=0;
s:='';
s1:='';
while(i<RSValue.Length*2)do
begin
s:=s+Buffer[i]+Buffer[i+1]+' ';
c:=RSValue.Value[i div 2];
if(c=#0)then
c:='0'
else if(c=#13)then
c:=''
else if(c=#10)then
c:=''
else if(c<#32)then
c:=' ';
s1:=s1+c;
inc(j);
if(j mod 4=0)and(j<16)then
s:=s+'|';
if(j=16)then
begin
j:=0;
HexUniCodeEd.Content.AddLine(s);
PlainTextUniCodeEdit.Content.AddLine(s1);
s:='';
s1:='';
end;
inc(i, 2);
end;
if s<>'' then
begin
HexUniCodeEd.Content.AddLine(s);
PlainTextUniCodeEdit.Content.AddLine(s1);
end;
finally
FreeMem(Buffer);
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMySQLResultSetFieldViewerForm.HexUniCodeEdScroll(Sender: TCustomUnicodeEdit; DeltaX, DeltaY: Integer);
begin
if not FChanging then
begin
FChanging := True;
try
HexUniCodeEd.Update;
PlainTextUniCodeEdit.OffsetY := HexUniCodeEd.OffsetY;
PlainTextUniCodeEdit.Update;
finally
FChanging := False;
end;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMySQLResultSetFieldViewerForm.PlainTextUniCodeEditScroll(Sender: TCustomUnicodeEdit; DeltaX, DeltaY: Integer);
begin
if not FChanging then
begin
FChanging := True;
try
PlainTextUniCodeEdit.Update;
HexUniCodeEd.OffsetY := PlainTextUniCodeEdit.OffsetY;
HexUniCodeEd.Update;
finally
FChanging := False;
end;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
end.
|