Problem with TAdvMemo component (about wordwrap) - delphi

I am using TAdvMemo. My problem is with the WordWrap property. It works very well when I type text in the text area, but when I add a string to it in code, it has no effect.
I have set WordWrap property to: wwRightMargin and RightMargin property to 80, but not see other property that can help me, so i ask some idea as solve it?
i mean for example:
AdvMemo.Lines.Add(MyString);
where MyString is a string as: 'hello word'. When it is longer than 80 chars, and wrap is enabled, it should wrap to a new line, but instead it's all on the same line.

Try using AdvMemo.InsertText instead. Lines.Add doesn't care about wrapping, it just handles some special chars in the string.

After you added text to adv memo you must update wrap by calling UpdateWrap() function. Here is an example for you:
AdvMemo.Lines.Add(MyString);
AdvMemo.UpdateWrap();
or
AdvMemo.Lines.Text(MyString);
AdvMemo.UpdateWrap();
Be sure that WordWrap property of Adv Memo is different than wwNone.

Related

TURLEncoding.Base64.Encode adds Linebreak?

It seems that URLEncoding.Base64.Encode adds a linebreak in long strings. Can I turn that off somehow? I didnt find any properties for that...
There is TBase64Encoding.Create(CharsPerLine: Integer) constructor. When CharsPerLine <= 0, then encoder will stop to add line breaks. In this case encoder must be created and destroyed explicitly.

Pharo Smalltalk: How to create an input field using TextMorph and then get the data off the input field?

I am completely new to Pharo, Smalltalk. I'm developing a small app that will convert temperature from Fahrenheit to Celsius. Can anyone give me any idea on how to create an input field using TextMorph and display it on a window as shown in the screen shot. In addition, being able to get the data back from the input field when the button is clicked. The below code is what I have done so far.
Screenshot
The class TemperatureMorph
BorderedMorph subclass: #TemperatureMorph
instanceVariableNames: 'tempInputField counter'
classVariableNames: ''
package: 'Assignment'
The initialize method: Contains a label, textbox and a button.
initialize
| headingLabel converterButton|
super initialize.
self bounds: (0#0 corner:300#300).
self color: Color gray.
headingLabel := StringMorph contents: 'Converter'.
headingLabel position: 130#20.
self addMorph: headingLabel.
tempInputField := TextMorph new.
tempInputField position: 50#50.
self addMorph: tempInputField.
Thanks
On a side not, if you're doing UI stuff in Pharo for anything other than learning (It looks like OP /is/ learning, so this probably doesn't apply). You should be looking at either Glamour or Spec. Both of which have really easy text input and control systems.
Spec
Glamour
You can already see the necessary code in your screenshot, you only have to replace the construction of a StringMorph with that of a TextMorph. I suggest you take a look at the Pharo by Example book. It has a chapter on Morphic, which is the UI framework in Pharo.
yourTextMorph := TextMorph new.
yourTextMorph contents: 'initial text'.
ownerMorph addMorph: yourTextMorph.
I guess you will also want to read the contents back out of the TextMorph. You can use yourTextMorph contents to achieve that. See also Pharo Smalltalk: Reading from TextMorph

Long strings in system Keyboard plist settings

I try add my own characters in keyboard.
I expand key 'z' by code to "Keyboard-en.plist":
"Roman-Accent-z" = {
Keycaps = "z mylongstringtitle ..."; // ... == \U017e \U017a \U017c characters ('z' with apostrophes and dots)
Strings = "z mylongstringvalue ...";
};
But keyboard not shown my string 'mylongstringtitle', only blank space ' ':
I can add only string 4 chars length on normal font and 7 chars on small font on 'button'. But I need add a long string.
Can I add 'mylongstringtitle' inside keycaps's string? May be I need set special parameters for long string? This is possible?
I don't think you will be able to add long string to be displayed in keyboard-en.plist. I believe the limitations of 4/7chars that you discovered are hard-coded in desire to avoid disfigured popup.
This keyboard behavior is not supported by Apple (it's not documented on http://developer.apple.com, or http://devforums.apple.com). Use of this feature in your app, therefore, is undefined behavior, which is considered programmer error.
That said, it's a neat feature. The limits of 4 and 7 characters for keycaps are hardcoded on iOS. I can't find them in any of the keyboard plists. You'd probably have to modify the keyboard binary to do what you want. (On OS X, on the other hand, this limit does not exist.)
A few alternatives exist, which you might know about:
You could modify this custom keyboard project
You could assign a custom inputView to be displayed at the top of the system keyboard

RichEdit.PlainText seems to not affect anything

I'm trying to write something like rtf editor in BCB6 and I've encountered such problem while trying to add table to my RichEdit1:
RichEdit1->PlainText=true;
AnsiString ret=RichEdit1->Text;
ret.Insert(table, RichEdit1->SelStart);
RichEdit1->Text=ret;
RichEdit1->PlainText=false;
RichEdit1->Repaint();
This code adds formatted text (code of table) to the RichEdit1 instead of adding formatting code as plain text and displaying it like a table.
Am I doing it wrong, or it can be a problem with something else.
The PlainText property is only used by the Lines->LoadFrom...() and Lines->SaveTo...() methods, nothing else.
The Text property only operates on plain text. Reading the property extracts the RichEdit's textual content without formatting. Setting the property does not process RTF code at all, the RichEdit's textual content is replaced with the new text as-is.
If you want to insert RTF code into the RichEdit, especially if you don't want to overwrite the RichEdit's current content, you will have to use the EM_STREAMIN message directly. For example:
DWORD CALLBACK StreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
int numRead = reinterpret_cast<TStringStream*>(dwCookie)->Read(pbBuff, cb);
if (pcb) *pcb = numRead;
return 0;
}
TStringStream *strm = new TStringStream(table);
EDITSTREAM es = {0};
es.dwCookie = (DWORD_PTR) strm;
es.pfnCallback = &StreamInCallback;
SendMessage(RichEdit1->Handle, EM_STREAMIN, SF_RTF | SFF_SELECTION, reinterpret_cast<LPARAM>(&es));
delete strm;
Problem solved, formatting was not added because of table code was not in {} brackets, after adding them around table code and using SendMessage, program works well.

TAction.SecondaryShortCuts is language specific. How to set it correctly?

I just used the SecondaryShortCuts-Feature of Delphi's TAction. But Shortcuts are defined by Strings, like "F5" or "Shift+F5". Now the problem: On my German Windows the action doesn't fire, because the key "Shift" is called "Umsch" in German!
Does it mean the SecondaryShortCuts-Property is completely useless at design time, because nobody can create applications which work internationally with that?
I could set the key at runtime by translating the VK_SHIFT into the correct name. I tried it via GetKeyNameText but this didn't worked because it gave the long form "Umschalt" not "Umsch". Anybody know the function to get the short version of the key name?
You could try this: Generate the shortcut text from a shortcut:
var
s: TShortCut;
begin
s := ShortCut(Ord('A'), [ssShift]);
Action1.SecondaryShortCuts.Add(ShortCutToText(s));
By the way, these values are determined by the following constants. Have you translated those? And if so, do you need to?:
SmkcShift = 'Shift+';
SmkcCtrl = 'Ctrl+';
SmkcAlt = 'Alt+';

Resources