我創建了一個簡單的Opendialog,EDIT1與展會消息圖像尺寸德爾福
我不知道爲什麼我的函數返回:
[DCC Error] Unit1.pas(112): E2010 Incompatible types: 'string' and 'tagSIZE'
完整的代碼是:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Types, ExtDlgs;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Memo1: TMemo;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
// procedure GetGIFSize(const sGIFFile: string; var wWidth, wHeight: Word);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetGIFSize(const FileName: string): Windows.TSize;
type
// GIF header record
TGIFHeader = packed record
Sig: array[0..5] of AnsiChar; // signature bytes
ScreenWidth, ScreenHeight: Word; // logical screen width and height
Flags: Byte; // various flags
Background: Byte; // background colour index
Aspect: Byte; // pixel aspect ratio
end;
// GIF image block header record
TGIFImageBlock = packed record
Left, Top: Word; // image top left
Width, Height: Word; // image dimensions
Flags: Byte; // flags and local colour table size
end;
const
cSignature: PAnsiChar = 'GIF'; // gif image signature
cImageSep = $2C; // image separator byte
var
FS: Classes.TFileStream; // stream onto gif file
Header: TGIFHeader; // gif header record
ImageBlock: TGIFImageBlock; // gif image block record
BytesRead: Integer; // bytes read in a block read
Offset: Integer; // file offset to seek to
B: Byte; // a byte read from gif file
DimensionsFound: Boolean; // flag true if gif dimensions have been read
begin
Result.cx := 0;
Result.cy := 0;
if (FileName = '') or not SysUtils.FileExists(FileName) then
Exit;
FS := Classes.TFileStream.Create(
FileName, SysUtils.fmOpenRead or SysUtils.fmShareDenyNone
);
try
// Check signature
BytesRead := FS.Read(Header, SizeOf(Header));
if (BytesRead <> SizeOf(TGIFHeader)) or
(SysUtils.StrLComp(cSignature, Header.Sig, 3) <> 0) then
// Invalid file format
Exit;
// Skip colour map, if there is one
if (Header.Flags and $80) > 0 then
begin
Offset := 3 * (1 shl ((Header.Flags and 7) + 1));
if Offset >= FS.Size then
Exit;
FS.Seek(Offset, Classes.soFromBeginning);
end;
DimensionsFound := False;
FillChar(ImageBlock, SizeOf(TGIFImageBlock), #0);
// Step through blocks
FS.Read(B, SizeOf(B));
while (FS.Position < FS.Size) and (not DimensionsFound) do
begin
if B = cImageSep then
begin
// We have an image block: read dimensions from it
BytesRead := FS.Read(ImageBlock, SizeOf(ImageBlock));
if BytesRead <> SizeOf(TGIFImageBlock) then
// Invalid image block encountered
Exit;
Result.cx := ImageBlock.Width;
Result.cy := ImageBlock.Height;
DimensionsFound := True;
end;
FS.Read(B, SizeOf(B));
end;
finally
FS.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Size: Windows.TSize;
begin
Size := GetGIFSize('file.gif');
ShowMessage(Size);
end;
end.
我用簡單:
GetGIFSize(路徑/到/文件名);
但文件名是一個字符串,你有任何想法,爲什麼不工作?
你試圖到'GetGIFSize'函數的結果分配給'string'類型的變量,而不是'Windows.TSize'。這是我們在你的問題中缺少的一段代碼。 – TLama 2013-05-11 00:10:22
@TLama打我給它 – 2013-05-11 00:10:47
請張貼你得到確切的**,整個編譯器錯誤**,沿加襯它與發生的事情,和** **確切您使用的是調用函數的代碼。說「我簡單地使用」還不夠好(正如@TLama指出的那樣)。 –
2013-05-11 00:11:55