## Hints and FAQ

Q1: How can I load the contents of an AnsiString or WideString?

A: You should do it using OpenStream method, giving it a TMemoryStream as a parameter. Sample procedures for AnsiString and WideString are shown below. Note that you should free stream only after calling Viewer.OpenStream(nil), otherwise control will try to read deallocated memory on scrolling!

//Viewer: TATBinHex field //MS: TMemoryStream field procedure TFormView.LoadAnsiString(const S: string); begin if not Assigned(MS) then MS := TMemoryStream.Create; MS.SetSize(Length(S)); if S <> '' then begin MS.Position := 0; MS.WriteBuffer(S[1], Length(S)); end; Viewer.Mode := vbmodeText; Viewer.OpenStream(MS); end; procedure TFormView.LoadWideString(const S: WideString); begin if not Assigned(MS) then MS := TMemoryStream.Create; MS.SetSize(Length(S) * 2); if S <> '' then begin MS.Position := 0; MS.WriteBuffer(S[1], Length(S) * 2); end; Viewer.Mode := vbmodeUnicode; Viewer.OpenStream(MS); end; procedure TFormView.EmptyViewer; begin Viewer.OpenStream(nil); if Assigned(MS) then FreeAndNil(MS); end;

Q2: I have an issue with horizontal scrollbar. Even when text becomes short enough, scrollbar doesn't disappear...

A: This is done as workaround for Windows XP bug: when scrollbar is about to disappear, this may cause both scrollbars and window border to disappear. You can disable this workaround by commenting the "HSCROLLBAR_WORKAROUND" define in ATBinHexOptions.inc.

The RichEdit control doesn't have this problem because it precalculates widths for all strings and sets scrollbar size to the max value. We cannot do this in ATBinHex control, so the scrollbar size is calculated dinamically.