Q: How can I reproduce this PreEdit using gmsl?
Code Block |
---|
<Replace>
<OldBlock><![CDATA[If (Ctrl = vbChecked) Then]]></OldBlock>
<NewBlock><![CDATA[If (Ctrl.Value = vbChecked) Then]]></NewBlock>
</Replace> |
A: The PreEditor is optimized for speed and ease of use, however it has a few limitations so in certain special cases a custom gmSL preEditor may be desired. The following example shows how this may be done.
1) Prepare an ServiceMethod_EditSource Handler in a gmSL script:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
int ServiceMethod_EditSource(int fileRoot) { tInfoFile fileInfo; Handle textStream; int rai; int length; string record; int nRecord; int curRecord; int iPos; fileInfo = Store.GetVector(fileRoot); if(fileInfo.textBase == 0) return 0; textStream = Text.Open(Store.GetHandle(),fileInfo.textBase); nRecord = Text.Maximum(textStream); curRecord = 0; while(curRecord < nRecord) { curRecord = curRecord + 1; Text.Position(textStream,curRecord); record = Text.Access(textStream, length, rai, 0); int curLen = sizeof(record); System.LogMessage(curRecord + "] " + curLen + ": " + record); if(length < 27) continue; iPos = Character.FindFirst(record, 0, "If (Ctrl = vbChecked) Then"); if(iPos == 0) continue; if(Select.Progress) System.LogMessage("Found 'If (Ctrl = vbChecked) Then' in <" + Store.GetIdent(fileRoot) + "> Record = " + curRecord); iPos = Character.FindFirst(record, 0, "Ctrl"); record = Character.Insert(record, iPos+3, ".Value"); if(Select.Progress) System.LogMessage("Fixed : " + record); Text.Position(textStream,curRecord); Text.Delete(textStream); Text.Position(textStream,curRecord - 1); Text.Insert(textStream, record); } Text.Close(textStream); return 1; } |
...