procedure ParaSecured(DasDataSet : TComponent;
Parametername :
String;
DataType : TFieldType;
Wert : Variant;
PicOrMemo : TObject =
nil);
var AStream : TMemoryStream;
DerParam : TParam;
DerParameter : TParameter;
IsAdo : Boolean;
begin
DerParam :=
nil;
DerParameter :=
nil;
if DasDataSet
is TQuery
then begin
IsAdo := False;
DerParam := TQuery(DasDataSet).ParamByName(Parametername);
DerParam.DataType := DataType;
end else if DasDataSet
is TStoredProc
then begin
IsAdo := False;
DerParam := TStoredProc(DasDataSet).ParamByName(Parametername);
DerParam.DataType := DataType;
end else if DasDataSet
is TAdoQuery
then begin
IsAdo := True ;
DerParameter := TAdoQuery(DasDataSet).Parameters.ParamByName(Parametername);
DerParameter.DataType := DataType;
end else if DasDataSet
is TADOCommand
then begin
IsAdo := True ;
DerParameter := TADOCommand(DasDataSet).Parameters.ParamByName(Parametername);
DerParameter.DataType := DataType;
end else if DasDataSet
is TADOStoredProc
then begin
IsAdo := True ;
DerParameter := TADOStoredProc(DasDataSet).Parameters.ParamByName(Parametername);
DerParameter.DataType := DataType;
end else if DasDataSet
is TBetterADOQuery
then begin
IsAdo := True ;
DerParameter := TBetterADOQuery(DasDataSet).Parameters.ParamByName(Parametername);
DerParameter.DataType := DataType;
end else if DasDataSet
is TBetterADODataSet
then begin
IsAdo := True ;
DerParameter := TBetterADODataSet(DasDataSet).Parameters.ParamByName(Parametername);
DerParameter.DataType := DataType;
end else raise Exception.Create('
Fehler in ParSecure:'+#13#10+
'
Komponente DasDataSet kennt keine Parameter...');
if IsAdo
then begin
if not Assigned(DerParameter)
then raise Exception.Create('
Fehler in ParSecure:'+#13#10+
'
Parameter nicht gefunden!');
end else begin
if not Assigned(DerParam)
then raise Exception.Create('
Fehler in ParSecure:'+#13#10+
'
Parameter nicht gefunden!');
end;
if Assigned(PicOrMemo)
then begin
AStream := TMemoryStream.Create;
try
case DataType
of
ftBlob,ftMemo,ftOraBlob,ftOraClob,ftFmtMemo,ftGraphic :
begin
if (PicOrMemo
is TBitmap)
and (DataType
in [ftBlob,ftOraBlob,ftGraphic])
then begin
TBitmap(PicOrMemo).SaveToStream(AStream);
end else if (PicOrMemo
is TPicture)
and (DataType
in [ftBlob,ftOraBlob,ftGraphic])
then begin
TPicture(PicOrMemo).Bitmap.SaveToStream(AStream);
end else if (PicOrMemo
is TLsPictureFrame)
and (DataType
in [ftBlob,ftOraBlob,ftGraphic])
then begin
TLsPictureFrame(PicOrMemo).Ls_Bitmap.SaveToStream(AStream);
end else if (PicOrMemo
is TMemo)
and (DataType
in [ftBlob,ftOraBlob,ftOraClob,ftMemo,ftFmtMemo])
then begin
TMemo(PicOrMemo).Lines.SaveToStream(AStream);
end else if (PicOrMemo
is TRichEdit)
and (DataType
in [ftBlob,ftOraBlob,ftOraClob,ftMemo,ftFmtMemo])
then begin
TRichEdit(PicOrMemo).Lines.SaveToStream(AStream);
end
else raise Exception.Create('
Fehler in ParSecure:'+#13#10+
'
PicOrMemo kein unterstütztes Objekt!'+#13#10+
'
Kann daher keine Binärdaten aus Objekt in Parameter streamen!');
end;
else raise Exception.Create('
Fehler in ParSecure:'+#13#10+
'
DataType passt nicht zu PicOrMemo oder'+#13#10+
'
DataType nicht ftBlob,'+#13#10+
'
ftMemo,'+#13#10+
'
ftOraBlob,'+#13#10+
'
ftOraClob,'+#13#10+
'
ftFmtMemo oder '+#13#10+
'
ftGraphic'+#13#10+
'
Kann daher keine Binärdaten aus Objekt in Parameter streamen!');
end;
// case
if IsAdo
then DerParameter.LoadFromStream(AStream,DataType)
else DerParam .LoadFromStream(AStream,DataType);
finally
AStream.Free;
end;
end else begin // kein TObject übergeben also Wert benutzen
if IsAdo
then DerParameter.Value := Wert
else DerParam .Value := Wert;
end;
end;