Untested and there're probably some errors but it should be something like this:
sveBerichte.FileName := cmbDownload.Text;
If not sveBerichte.execute then
Exit;
filepath := sveBerichte.Filename;
hexstring := '';
{I'll assume al this works as it should}
quyBerichte.close;
quyBerichte.SQL.Text := 'Select bericht from eberichte where nr = :nr';
quyBerichte.Params.ParambyName('nr').AsString := cmbdownload.text;
quyBerichte.open;
hexstring := quyBerichte.Fields[0].AsString;
quyBerichte.close;
HStream := TStringStream.Create(hexstring);
try
Stream := TFileStream.Create(filepath, fmCreate);
try
HStream.Seek(0, soFromBeginning); {Murphy-guard!}
{CByte is declared as String[2], isn't it?}
while HStream.Read(CByte[1], 2) > 0 do
Stream.Write(chr(StrToInt('0x' + CByte)));
finally
Stream.Free;
end;
finally
HStream.Free;
end;
end;
Your hexstring contains hexadecimal
characters which you must convert back to integer; this can be done with (among others)
StrToInt(). Then you can use
Chr() to convert the byte to a character which, finally, is saved to the file. Note than I'm here assuming: 1) reading the database works as it should; and 2)
CByte is declared as a
String[2]. If it's not then this won't work at all.
Quite frankly, I wouldn't implement this feature as this, needing so may conversion back and forth. I would use a BLOB field (or similar) and read/write the file as is. But to each their own, I guess